默认帐户控制器在服务器 ASP.NET MVC 5 上不起作用

Default Account Controller does not work on server ASP.NET MVC 5

我制作了一个 ASP.MET MVC5 应用程序。这在 Visual Studio 上非常有效。我在 ASP.NET MVC 5 中使用默认用户帐户。对于用户帐户,它创建了一个名为 aspnet-Books-20150119023687 的数据库。然后我做了一个连接字符串。它不使用该数据库(我不知道它在使用什么)但默认帐户控制器仍在工作。然后我将我的代码上传到服务器。一切正常,但是当我打电话给 mysite/Account/Register 并尝试注册时,我收到了这些错误:

[Win32Exception (0x80004005): The system cannot find the file specified]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]

我应该怎么做才能使默认帐户控制器在服务器上工作?我被告知我需要将一些数据上传到服务器,但我不知道要上传什么。谢谢。

编辑: 默认连接字符串是这样的:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-Books-20150114567898.mdf;Initial Catalog=aspnet-Books-20150119023806;Integrated Security=True" providerName="System.Data.SqlClient" />

然后我将连接字符串更改为:(这没有用)

<add name="BooksContext" providerName="System.Data.SqlClient" connectionString="Data Source=SERVER06\SQLSERVER2005EX;Initial Catalog=booksdb; User ID=admin; Password=123456"/>

然后我改成了这个,这个也没用:

<add name="BooksContext" providerName="System.Data.SqlClient" connectionString="Data Source=SERVER06\SQLSERVER2005EX; AttachDbFilename=|DataDirectory|\aspnet-Books-20150114567898.mdf;Initial Catalog=booksdb; User ID=admin; Password=123456"/>

您说您有 SQL 服务器完整版,而 "AttachDbFilename" is used only in SQL Express。也许这是你的问题。

您还需要将 mdf 文件附加到 SQL 服务器完整版。 https://msdn.microsoft.com/en-us/library/ms190209.aspx

修改本地 web.config 的连接字符串

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-Books-20150114567898.mdf;Initial Catalog=aspnet-Books-20150119023806;Integrated Security=True" providerName="System.Data.SqlClient" />

到您本地的 sql 服务器连接字符串 例如如下所示

<add name="DefaultConnection" connectionString="Data Source=SERVER06\SQLSERVER2005EX;Initial Catalog=booksdb; User ID=admin; Password=123456" />

然后运行你的本地应用程序,在本地机器上注册用户。

现在在服务器上发布后,将此连接字符串从 web.config 修改为指向服务器数据库位置,它将正常工作。