Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VisualStudio2012
Hi all,
I am using visual studio 2012,framework 4.0,
I am trying to connect to the local db using connection string

SqlConnection con = new SqlConnection(@"Server=(localdb)\v11.0;Integrated Security=true;Database=Practice;");

But I am getting the exception as follows:-

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)

Please advice,Am I missing something?

Regards
Posted 5-May-13 0:55am
Comments
ThePhantomUpvoter at 5-May-13 8:14am
   
You are incorrectly specifying the server name in your connection string.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First and foremost make sure that the SQL Server services are running. Other reasons could be, incorrect connection string or some Firewall blockage.
 
Here, have a look at this blog post to troubleshoot the issue : MSDN Blogs: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified[^]
 
If needed, look at these one:
Exception - error 26 - Error Locating Server Instance Specified[^]
provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance...[^]
"Specified SQL server not found" o..[^]
  Permalink  
Comments
DotnetCoders001 at 10-May-13 11:20am
   
Appriciate your reply.I found a solution as follows :-
Went to Tools->Connect to database, specified server name as (localdb)\v11.0 and then selected the appropriate database from the list and it worked.

But, after closing the application when I reopen my application and reconnect to the local db sometimes it gives error 26,any idea why sometimes it works and sometimes throws this error?
Sandeep Mewara at 10-May-13 11:45am
   
Hard to say.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

The connection string you are using is wrong.
Please try to use the correct one according to your configurations.
 
For that you have one awesome website - http://www.connectionstrings.com/[^].
 
Search for the required connection string according to the database and technology.
 
For Example (SQL Server 2008) - Connection strings for SQL Server 2008[^].
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
 
For Local DB, you can just provide a dot "." instead of (localdb)\v11.0.
 
So, you can try with the below one...
Server=.;Database=Practice;User Id=myUsername;Password=myPassword;
Provide necessary UseName and Passwords.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

My error 26 was solved by updateing the .Net Framework to 4.5
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 132
2 ProgramFOX 130
3 Maciej Los 105
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 1 Nov 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100