Click here to Skip to main content
11,932,446 members (54,799 online)
Rate this:
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 11:11am
Edited 19-Oct-12 11: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 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
Top Experts
Last 24hrsThis month

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