Link to home
Start Free TrialLog in
Avatar of PC_tech22
PC_tech22

asked on

Can't connection to SQL Server Database System.Data.SqlClient.SqlException was unhandled

I am just trying to connect to Northwind and Pubs

         Dim myConnection As New SqlConnection("Database=Pubs;Server=(local);UID=sa;PWD=;")
        Dim myCommand As New SqlCommand
        myConnection.Open()

        myCommand.Connection = myConnection
        myCommand.CommandType = CommandType.Text
        myCommand.CommandText = "select * from titles"

        Dim daEmp As New SqlDataAdapter(myCommand)
        Dim dsEmp As New DataSet


        daEmp.Fill(dsEmp, "Employees")
        gvEmp.DataSource = daEmp

I don't want to be a DBA just a Developer,  with full permissions to the data,  :( it is holding me back

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Hillwaaa
Hillwaaa
Flag of Australia image

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 PC_tech22
PC_tech22

ASKER

Where the difference?
I don't see it
PWD=;"
should be
PWD=";
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

What is myServerAddress?
Dim myConnection As New SqlConnection("Initial Catalog=Pubs;Server=(local);UID=sa;PWD=")

This is what I have so far
Is there something in the SQL Server Manager that I can obtain the connection string?

Thanks for your help.
PC_tech22,

The difference is the try...catch block.  It will show the error - whether it's a password issue or not.
oh ok

        Dim myConnection As New SqlConnection("data source=(local); database=Northwind; Trusted_Connection=yes;") '("Initial Catalog=Pubs;Server=(local);UID=sa;PWD=")
        Dim myCommand As New SqlCommand
        myConnection.Open()

        myCommand.Connection = myConnection
        myCommand.CommandType = CommandType.Text
        myCommand.CommandText = "select * from Employees"

        Dim daEmp As New SqlDataAdapter(myCommand)
        Dim dsEmp As New DataSet


        daEmp.Fill(dsEmp, "Employess")
        gvEmp.DataSource = daEmp

It is past the Connection.open problem but does not show in the GridView
You may not be able to see it but the old connection string is commented out
I also changed to use the NorthWind database
try changing   gvEmp.DataSource = daEmp to

  gvEmp.DataSource = dsEmp
It still doesn't work
...and no .databind method
Also I have another Question Open for more points.
Hi PC_tech22 - you should probably close this question and give points to the experts that helped with your connection problem.  

The other question should then give you an answer on how to setup your data bindings.  EE states that the max points for any particular question is 500, so I don't want to answer the same question in both :)

Cheers,
Hillwaaa.
Your're right sorry!:)

Ok other on to other question.    
Thank you for your Help with this question.
How exactly did the accepted answer fix the connection problem???