We help IT Professionals succeed at work.

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

PC_tech22
PC_tech22 asked
on
557 Views
Last Modified: 2007-02-02
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
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Where the difference?
I don't see it
PWD=;"
should be
PWD=";

Author

Commented:
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

What is myServerAddress?

Author

Commented:
Dim myConnection As New SqlConnection("Initial Catalog=Pubs;Server=(local);UID=sa;PWD=")

This is what I have so far

Author

Commented:
Is there something in the SQL Server Manager that I can obtain the connection string?

Thanks for your help.

Commented:
PC_tech22,

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

Author

Commented:
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

Author

Commented:
You may not be able to see it but the old connection string is commented out

Author

Commented:
I also changed to use the NorthWind database

Commented:
try changing   gvEmp.DataSource = daEmp to

  gvEmp.DataSource = dsEmp

Author

Commented:
It still doesn't work
...and no .databind method
Also I have another Question Open for more points.

Commented:
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.

Author

Commented:
Your're right sorry!:)

Ok other on to other question.    

Author

Commented:
Thank you for your Help with this question.
How exactly did the accepted answer fix the connection problem???
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.