Establishsing database connection

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...
 
A

Alberto Poblacion

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...".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top