SQLConnection

JoeVB

Member
Joined
May 10, 2005
Messages
6
Programming Experience
5-10
I am not new to VB but am new to the classes in VB.net

I have a simple project so far:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SqlConn1.Open()
Dim sqlReader As SqlDataReader = SqlCmd1.ExecuteReader(CommandBehavior.CloseConnection)
While sqlReader.Read
cmbRegions.Items.Add(sqlReader.GetString(0))
End While
sqlReader.Close()
End Sub


To start I dropped the SqlConnection icon (from the Data toolbox) onto my form. I then used the wizard and made a connection string, test succeeded.
I then dropped a SQLCommand object onto my form, specified the Connection as the SQLConnection above. I then create a CommandText for the SQLCommand object.

When I run the above code I get an error:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.

This breaks on the SqlConn1.Open() line.

Anyone know what I am missing here? I have made connections before but never using the objects, I would always create my own.
 
Back
Top