Solved

VB.net Cannot open connection to SQLExpress 2005

Posted on 2007-03-26
6
414 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:josh261
Comment Utility
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
Comment Utility
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
Comment Utility
That worked.  I just needed to add Data Source=localhost\sqlexpress in the connections string.

Thanks for your help!  You  rock!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now