Link to home
Start Free TrialLog in
Avatar of josh261
josh261

asked on

VB.net Cannot open connection to SQLExpress 2005

Hello.  I am having problems finding out why I cannot open a connection to my local SQLExpress instance from a vb.net form.  I have looked all over the internet, but nothing I have tried works.  Can anyone offer help?  Thanks!!
Here is my code...it bombs at the last line where the connection is opened.

        Dim ConnStr As String = "Server=localhost;DataBase=TableDining;User Id=myName;Password=pwd@1!"
        Dim sqlConnection As New Data.SqlClient.SqlConnection(ConnStr)
        Dim strSQL As String = "SELECT * FROM table WHERE (PIN = 1111)"
        Dim cmd As New Data.SqlClient.SqlCommand(strSQL, sqlConnection)
        cmd.CommandType = CommandType.Text
        cmd.Connection.Open()
     
Avatar of dstanley9
dstanley9

what error do you get?  connection strings can be cae-sensitive, so try

Dim ConnStr As String = "Server=localhost;Database=TableDining;User ID=myName;Password=pwd@1!"

(notice the change to Database and User ID)
Avatar of josh261

ASKER

Thanks for the quick response!!

I tried what you suggested and still get the same error.  Here's the error message I get:

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.
Avatar of josh261

ASKER

Great article!!

I tried all of the things it said...and thought it should work but didn't.  

One of the suggestions is made when finished was to use the command prompt utility OSQL to simulate a remote connection client.  OSQL connected with no problems.

Could it be something with Visual Studio or the vb.net code?
ASKER CERTIFIED SOLUTION
Avatar of dstanley9
dstanley9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of josh261

ASKER

That worked.  I just needed to add Data Source=localhost\sqlexpress in the connections string.

Thanks for your help!  You  rock!