954,202 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

VB.Net and sql server connection

I'm tyring to connect to the sql server on my lcoal machine and have this error.
"An error has occured establishing connection to the server. Failure may be caused by the fact that under the default settings SQL server does nto allow remote connections.(provider:Named Pipes Provider,error 40 - could not open a connection to sql server)"

Can someone help me fix this?

Thanks

pvi
Newbie Poster
5 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

can you post your code

Sawe
Newbie Poster
6 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

Is it SQL express or the full version?
If so what version is it?

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,820
Solved Threads: 600
 
can you post your code


The code is as follows:

Dim strConn As String = "Integrated Security=True;" & _
"Initial Catalog=Cargo;" & _
"Data Source=localhost"

pvi
Newbie Poster
5 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 
Is it SQL express or the full version? If so what version is it?

It's the SqlServer express edition downlaoded from the net. Do I need to make changes to the settings in the configuration Manager?

Thanks.

pvi
Newbie Poster
5 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

Try instead of localhost --> localhost\SQLEXPRESS

Proteus
Newbie Poster
5 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

yes, try that

If that doesnt work you may need to mess about with the config (sql express is set up to be secure by default, so only the local machine can connetc to it. some code doesnt like this)

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,820
Solved Threads: 600
 

do like this.

connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
connection = New SqlConnection(connetionString)

jannet.

janet_ss
Newbie Poster
4 posts since Apr 2008
Reputation Points: 4
Solved Threads: 0
 

Erm, you know this thread is like 2 years old?

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

cn.connectionstring="Server =server name;database=dbasename;UID= id;PWD=password"

Rashmi Awasthi
Newbie Poster
1 post since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Hi,

I now this thread is like intially two years old but I keep seeing people trying to connection to the SQL express instance using ServerName.

SQLExpress always installs its instance as ServerName\SQLEXPRESS

N.B. You can have as may instances of SQL running on the same machine as you wish but only one can be the default ServerName instance the rest will all be ServerName \InstanceName

This is actually handy if you want to put two diffeerent version of SQL on the same machine e.g. Servername\SQL2000 ServerName\SQL2005 or seperate differnet apps on to different instances for security purposes

There rant over I feel better now...

G_Waddell
Posting Whiz in Training
240 posts since Nov 2009
Reputation Points: 37
Solved Threads: 25
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You