Link to home
Start Free TrialLog in
Avatar of vmandem
vmandem

asked on

Hi how do I connect to my sqlserver database from VB.NET

I'm using the connection string like this:

Dim strconnection = "Server=local;Database=VM;User ID=sa;Password=hello;Trusted_Connection=False"

and this is the code I'm using to open the connection

   Dim oSQLConn As SqlConnection = New SqlConnection
        oSQLConn.ConnectionString = strconnection
        oSQLConn.Open()

But I get the error like this:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Additional information: System error.

What could be the problem. I checked the sqlserver and I set the username and password for the VM database as
"sa" and "hello"

Thanks
vm
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Can connect to SQL Server with Windows Authentication?

Bob
Avatar of vmandem
vmandem

ASKER

TheLearnedOne

I got connected to the sqlserver and I changed the server name and it worked. Can you please tell me how to retreive data from the sql query to a recordset and I want to pass the recordset value to a textbox.

Thanks and appreciate your help.
vm
ASKER CERTIFIED SOLUTION
Avatar of wguerram
wguerram

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
You need to fill in the holes:


Dim connectionSQL As SqlConnection = New SqlConnection(connectionString)

conn.Open()

Dim commandGetData As SqlCommand = New SqlCommand(queryString, connectionSQL)

Me.TextBox1.DataBindings.Add(New Binding("Text", DataSet1, "Table.Field"))

Bob
Right at the same time!!!

Bob