Zero Sense
Zero Sense

Reputation: 3

visual studio 2017 web application mvc SqlException (0x80131904) error

Ive been working on a web app for the past month and now its time to deploy it on real windows server.The problem is once i deployed it my default localdb code first SQL database no longer works with this code:

[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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details. )]

Source Error:

Line 11:         var manager = new UserManager();
Line 12:         var user = new ApplicationUser() { UserName = UserName.Text };
Line 13:         IdentityResult result = manager.Create(user, Password.Text);
Line 14:         if (result.Succeeded)
Line 15:         {

my web.config string :

  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346;AttachDbFilename=|DataDirectory|\aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346.mdf;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
  </connectionStrings>

Its so frustrating im kinda lost , i dont want to build my login and registration from scratch i just want to use the provided ones from Visual Studio 2017 and there is no tutorial up to date how to do it.

I have SQL Express on my computer installed and its currently running.

Upvotes: 0

Views: 688

Answers (1)

Tetsuya Yamamoto
Tetsuya Yamamoto

Reputation: 24957

There are possible solutions to solve LocalDB instance issue:

1) If the database is already created (as given by AttachDbFilename=|DataDirectory|\aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346.mdf), remove the section so that it only contains Initial Catalog shown below.

<connectionStrings>
     <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>

2) Set IIS application pool for the MVC application to either LocalSystem or NetworkService from ApplicationPoolIdentity - if you suspect a permission-related issue for the application.

3) Find out \%WinDir%\System32\inetsrv\config\applicationHost.config file and enable setProfileEnvironment="true" (restart the application pool afterwards):

<!-- use application pool name depending which pool that your MVC site used -->
<add name="DefaultAppPool" ...>
    <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>

Further references:

Similar issue:

Upvotes: 1

Related Questions