0

我已经完成了本教程: https ://www.windowsazure.com/en-us/develop/net/tutorials/web-site-with-sql-database/?redirectToLocale=false

当我在我的 Azure 在线帐户上发布它时它就可以工作,并且数据库运行良好。但问题是,当我按照教程进行操作时,它要求这样做:1. enable-migrations 2. add-migrations 3. update-database

  1. 和 2. 有效,但是当我在包管理器控制台中运行 3. (update-database) 时,我收到此错误:

数据库“master”中的 CREATE DATABASE 权限被拒绝。

所以我无法在本地部署我的网站,这是我的问题......当我运行 Ctrl+F5 时,它会打开

> http://localhost:2700/

它显示了这个错误:

> Server Error in '/' Application.
> 
> CREATE DATABASE permission denied in database 'master'.
> 
> Description: An unhandled exception occurred during the execution of
> the current web request. Check the stack trace for more information
> about the error and where it originated in the code.
> 
> Exception Details: System.Data.SqlClient.SqlException: CREATE DATABASE
> Permission denied in database 'master'.
> 
> Source Error:
> 
> 
> Line 20: public ActionResult Index ()
> Line 21: { 
> Line 22:   return View(db.ToDoItems.ToList ()); 
> Line 23: } 
> 
> Source File: c: \ Users \ baudouin \ Documents \ Visual Studio 2012 \
> Projects \ ToDoListApp \ ToDoListApp \ Controllers \ HomeController.cs
> Line: 22

当我打开 SQL Server Management Studio 时,我确实可以访问我的主数据库......当我在 Visual Studio 2012 RC 中时,它说我的数据连接 DefaultConnection(ToDoApp) 有一个错误:

> Server Explorer can not execute this operation.
>     For more information, see details below:
>     Cannot attach the file 'C:\Users\baudouin\documents\visual studio 2012\Projects\ToDoListApp\ToDoListApp\App_Data\aspnet-ToDoListApp-20120625114938.mdf'
> as database 'aspnet-ToDoListApp-20120625114938'.

我在教程中没有看到与 .mdf 相对应的内容......而且我不明白为什么 update-database 根本不起作用。

你能帮我么 ?

谢谢 !!【来自巴黎的法国学生】

4

2 回答 2

0

你的连接字符串是什么?您似乎在测试代码时尝试连接到本地 SQLExpress DB?

当您从 Visual Studio 运行代码时,VS 和数据库都可以在两个不同的帐户上运行。例如,Windows Azure Compute Emulator 使用“网络服务”帐户凭据运行,因此为主数据库添加相同的“网络服务”凭据可以解决问题。

因此,尝试为 NT AUTHORITY\NETWORK SERVICE 添加登录到您的 SQLExpress 实例并授予它 sysadmin 角色,看看问题是否已解决。

尽管授予 sys admin 角色授予 db_owner 角色到 NT AUTHORITY\NETWORK SERVICE 仅用于主 DB。这还需要重新启动服务一次,建议重新启动系统。

于 2012-06-26T18:00:54.213 回答
-1

正如 Avkash 所指出的,该问题与您尝试连接到本地数据库有关。这可能在本地有效,但在 Windows Azure 中无效。请使用 Azure SQL 数据库。连接字符串的数据源需要指向 tcp:... 而不是本地 mdf 文件。实际上您指出的教程已经使用了 Azure SQL 数据库,请参阅它以获取更多详细信息。

于 2012-07-03T10:09:35.023 回答