SOLVED

Problems with connection string for SQLserverexpress 2019

Copper Contributor

Hi

 

I am looking for help please. I am new to sqlserverexpress 2019 and experimenting at the moment to get familair with the system.

 

I have created a sqlserver using all the defaults on my local machine. I can access sql using SSMS19 no problem. I program in visual studio vb.net and i am trying to connect using a connection string:

 

Data Source=CHRIS-LAPTOP\SQLEXPRESS,1433;Persist Security Info=False;User ID=sa;Password=mypasswordhere;

 

But i get this error:

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: TCP PROVIDER, ERROR: 0 - NO CONNECTION COULD BE MADE BECAUSE THE TARGET MACHINE ACTIVELY REFUSED IT.)

 

Can anyone help please? with a basic connection string to get me going. The code I have in vb.net I know works as I can connect to a sql server online (azure) no problem.

the connection string for the online sql server (which works) is:

Server=tcp:myservername,1433;Initial Catalog=mydatabase;Persist Security Info=False;User ID=myloginname;Password=mypassword

 

 

 

Many Thanks for your help

 

Chris

 

 

 

 

1 Reply
best response confirmed by cjacs (Copper Contributor)
Solution

Hello Chris,

use either the instance name or the IP port, but not both. And in .NET you have to quote a backslash =>

 

Data Source="CHRIS-LAPTOP\\SQLEXPRESS;Persist Security Info=False;User ID=sa;Password=mypasswordhere"

 

Olaf

1 best response

Accepted Solutions
best response confirmed by cjacs (Copper Contributor)
Solution

Hello Chris,

use either the instance name or the IP port, but not both. And in .NET you have to quote a backslash =>

 

Data Source="CHRIS-LAPTOP\\SQLEXPRESS;Persist Security Info=False;User ID=sa;Password=mypasswordhere"

 

Olaf

View solution in original post