Solved

VB.net Cannot open connection to SQLExpress 2005

Posted on 2007-03-26
6
417 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
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.

 

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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

18 Experts available now in Live!

Get 1:1 Help Now