简体   繁体   中英

Issue connecting to databases ASP .NET MVC 5 SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified

I have been trying to fix this issue for half a day now. I am unable to connect to any database from my ASP.NET MVC 5 application.

I'm getting 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: 26 - Error Locating Server/Instance Specified)

My connection string looks like this :

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

This has worked in the past, until recently, I have deployed the application to Azure and this require starting VS 2013 as Administrator, and I thought it broken permissions, until I tried connecting to Azure SQL and that also failed.

I've tried restarting SQLLocalDB , which usually helped in the past.

I'm not sure where the problem is, when I create a new ASP .NET MVC application, I can connect to its .MDF database file without issues. However when I reference that new file in my application, it will not connect.

Any help appreciated.

Thank you

I have 'fixed' the issue by reverting to an earlier version of my application through Git.

I broke it again by installing WebMatrix.WebData NuGet Package, I am not why this happens, but I will just avoid installing it now.

I had a lot of issues like this for no apparent reason! Every time I ran the software locally it took longer and longer until 'bang' your error as described. Spent hours trying to solve it. Nothing.

Then I 'repaired' Visual Studio and Bingo !! All well again.

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