简体   繁体   English

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

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

I have made an ASP.MET MVC5 application. 我已经制作了一个ASP.MET MVC5应用程序。 That works perfectly on Visual Studio. 在Visual Studio上可以完美地工作。 I'm using default user accounts in ASP.NET MVC 5. For user accounts, it created a database named like aspnet-Books-20150119023687. 我在ASP.NET MVC 5中使用默认用户帐户。对于用户帐户,它创建了一个名为aspnet-Books-20150119023687的数据库。 Then I made a connection string. 然后我做了一个连接字符串。 It doesn't use that database(I don't know what it is using) but still default Account Controller is working. 它不使用该数据库(我不知道它在使用什么),但是默认的Account Controller仍在工作。 Then I uploaded my code to a server. 然后,我将代码上传到服务器。 Everything is working fine, but When I call mysite/Account/Register and try to get registered, I get these errors : 一切正常,但是当我致电mysite / Account / Register并尝试注册时,出现以下错误:

[Win32Exception (0x80004005): The system cannot find the file specified] [Win32Exception(0x80004005):系统找不到指定的文件]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. [SqlException(0x80131904):建立与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. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (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.)] (提供者:SQL网络接口,错误:52-无法找到本地数据库运行时安装。验证是否正确安装了SQL Server Express并启用了本地数据库运行时功能。)]

What should I do to have the default Account controller to work on server? 要使默认的帐户控制器在服务器上工作,我该怎么办? I was told that I need to upload some data to server but I don't know what to upload. 有人告诉我我需要将一些数据上传到服务器,但是我不知道要上传什么。 Thanks. 谢谢。

EDIT : The default connection string was this : 编辑:默认的连接字符串是这样的:

<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" />

Then I changed connection string to this : (this didn't work) 然后我将连接字符串更改为此:(这​​不起作用)

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

Then I changed to this, this didn't work either : 然后我改成了这个,这也不起作用:

<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"/>

You said you have SQL server full edition while "AttachDbFilename" is used only in SQL Express . 您说您拥有SQL Server完整版,而“ AttachDbFilename”仅在SQL Express中使用 Maybe that's your problem. 也许那是你的问题。

Also you need to attach the mdf file to the SQL server full edition. 另外,您需要将mdf文件附加到SQL Server完整版。 https://msdn.microsoft.com/en-us/library/ms190209.aspx https://msdn.microsoft.com/zh-CN/library/ms190209.aspx

Modify the Connection String from web.config on local 从本地的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" />

to your local sql server connection string eg like given below 到您的本地sql服务器连接字符串,例如下面给出的

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

Then run your local application, register user on local machine. 然后运行您的本地应用程序,在本地计算机上注册用户。

Now After Publishing on Server modify this Connection string from web.config to point to Server db location it will work fine. 现在在服务器上发布后,修改web.config中的此连接字符串以指向服务器数据库位置,它将可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM