Click here to Skip to main content
11,702,890 members (62,097 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 415
1 Sergey Alexandrovich Kryukov 325
2 OriginalGriff 260
3 CHill60 120
4 Andy Lanng 119
0 OriginalGriff 8,379
1 Sergey Alexandrovich Kryukov 7,587
2 CPallini 4,947
3 Maciej Los 4,501
4 Mika Wendelius 3,566

Advertise | Privacy | Mobile
Web02 | 2.8.150819.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