Click here to Skip to main content
Rate this: bad
good
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; 
cn.Open();
 
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
suraty455
Edited 19-Oct-12 11:18am
v3

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
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 315
1 OriginalGriff 233
2 Aajmot Sk 224
3 Richard MacCutchan 220
4 Marcin Kozub 210
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 19 Oct 2012
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