Click here to Skip to main content
11,795,848 members (82,432 online)
Rate this: bad
Please Sign up or sign in to vote.
I installed Sql Server 2008 R2 in win 7 32bit. It installed correctly and made a database. I opened visual studio 2010 and wrote a code that it connects to Sql server.
cn = new SqlConnection(); 
cn.ConnectionString = Data Source=(local); 
Initial Catalog=XXX_amlak; 
User ID=sa; password=XXX; 

but it has this error.
SQLException was unhandled 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:Named Pipes Provider,error:40-could not open a connection to SQL Server)

Visual Studio has installed SQL Express automatically.I disable my Internet security.
Posted 19-Oct-12 10:11am
Edited 19-Oct-12 10:18am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You have either one of two situations:
1) Your connection string is kaput and needs to be fixed (This is my assumption, as "(local)" is not likely a valid instance name. This value needs to reflect the proper instance name that you use when you logon using Management Studio. Usually something like 'localhost/INSTANCE', or 'MACHINENAME/INSTANCE'.
2) Your SQL server is not accepting remote connections.
suraty at 20-Oct-12 13:18pm
I am trying to connect to SQL Server Management Studio.

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

  Print Answers RSS
0 Maciej Los 410
1 Abhinav S 368
2 OriginalGriff 300
3 Sergey Alexandrovich Kryukov 266
4 KrunalRohit 249
0 OriginalGriff 1,852
1 Maciej Los 1,465
2 KrunalRohit 1,300
3 CPallini 840
4 Richard MacCutchan 828

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 19 Oct 2012
Copyright © CodeProject, 1999-2015
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