GeorgeB
GeorgeB

Reputation: 848

ASP.NET MVC cannot connect to my local SQL Server database

I have an ASP.NET MVC application and I cannot connect to the local SQL Server database that is hosted on my machine.

I get the following error:

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

I have recently installed SQL Server Express on top of the original SQL Server install; since this has happened, the application can now never get connected to the database. My app is running on the local IIS and under Administrator when I debug through Visual Studio.

Things I have tried:

I am getting the following errors in Computer Management under SQLLocalDB15.0:

The specified resource language ID cannot be found in the image file.

Cannot get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS, make sure that profile loading is enabled for the current user.

My Connection string is as follows:

<add name="Entities" connectionString="metadata=res://*/Models.DataModel.csdl|res://*/Models.DataModel.ssdl|res://*/Models.DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localdb)\MSSQLLocalDB;initial catalog=DatabaseName;integrated security=True;persist security info=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I have the following SQL stuffs installed on my machine, I don't know if they are having an effect here:

Programs and Features

Upvotes: 0

Views: 1835

Answers (2)

GeorgeB
GeorgeB

Reputation: 848

Solved the issue by uninstalling all of the SQL related stuff in my screenshot and re-installing the development SQL Server 2019, then I created the database I had before and connected to it using the data model in EntityFramework, and it worked!

Upvotes: 0

Serge
Serge

Reputation: 43860

The first thing you have to try is to use MS Sql Server Managemen Studio to connect to your Db using (localdb)\MSSQLLocalDB as server name and windows authentication. If it is empty you can attach db or create new. If it doesn't work you have to try to find your Db using Sql Studio search tools. If you can't find it you have to install your local db again and you will find your db name during the instalation. After this correct your db name accordingly. OR EVEN BETTER try to create your EF from your found db again. EF will automaticaly add the right connection string to your config file. After this you can change the name or move it to another config file.

Upvotes: 1

Related Questions