0

I installed SQL Server 2008 R2 and Visual Studio 2010 in my win7 32 bit. They were installed correctly. And each works well alone. But when I want to connect to SQL Server Management Studio from visual Studio I get this error. (I want to connect to a local data base):

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)

This is my code for connection:

cn = new SqlConnection();
cn.ConnectionString = "Data Source=(local); Initial Catalog=XXX_amlak; User ID=sa; password=XXX";
cn.Open();
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75

1 Answers1

1

Use this connectionstring to connect to local database:

cn.ConnectionString = "Data Source=.\SqlExpress; Initial Catalog=XXX_amlak; User ID=sa; password=XXX";

OR check out this question: How to connect to local instance of SQL Server 2008 Express

Community
  • 1
  • 1
avb
  • 1,558
  • 1
  • 14
  • 37