简体   繁体   中英

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

I have made an ASP.MET MVC5 application. That works perfectly on 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. 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. 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 :

[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.)]

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 . Maybe that's your problem.

Also you need to attach the mdf file to the SQL server full edition. https://msdn.microsoft.com/en-us/library/ms190209.aspx

Modify the Connection String from web.config on local

<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

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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