Establishsing database connection

  • Thread starter Thread starter Vicky
  • Start date Start date
V

Vicky

I have installed both SQL and visual studio 2005 in my computer having
vista. I tried to establish the database connection using this code:

SqlConnection conn = new SqlConnection("data source= VICKY-PC//
SQLEXPRESS; integrated security=yes;initial
catalog=master;Trusted_Connection=yes");
conn.Open();

But it is not working. It throws a run time error "An error has
occurred while establishing a connection to the server. When
connecting to SQL Server 2005, this failure may be caused by the fact
that under the default settings SQL Server does not allow remote
connections. (provider: Named Pipes Provider, error: 40 - Could not
open a connection to SQL Server)"

Can anyone tell me how to establish connection?? Plse give me brief
description as i am a beginner...
 
Vicky said:
I have installed both SQL and visual studio 2005 in my computer having
vista. I tried to establish the database connection using this code:

SqlConnection conn = new SqlConnection("data source= VICKY-PC//
SQLEXPRESS; integrated security=yes;initial
catalog=master;Trusted_Connection=yes");
conn.Open();

But it is not working. It throws a run time error "An error has
occurred while establishing a connection to the server.

The slash separating the server name from the instance name should be a
backslash, rather than the two forward slashes that you entered. Of course,
in the case of the backslash (but not the forward slash) you have to escape
it, doubling it inside the string: "...VICKY-PC\\SQLEXPRESS...".
 
Back
Top