Solved

VB.net Cannot open connection to SQLExpress 2005

Posted on 2007-03-26
6
419 Views
Last Modified: 2013-11-26
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()
     
0
Comment
Question by:josh261
  • 3
  • 3
6 Comments
 
LVL 25

Expert Comment

by:dstanley9
ID: 18793308
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)
0
 

Author Comment

by:josh261
ID: 18793399
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.
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 18793427
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:josh261
ID: 18794530
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?
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 500 total points
ID: 18794626
Can you create a Data Connection to the instance in Server Explorer?  If you can, look at the properties of the connection to get your connection string.
0
 

Author Comment

by:josh261
ID: 18794712
That worked.  I just needed to add Data Source=localhost\sqlexpress in the connections string.

Thanks for your help!  You  rock!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question