Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The Connection String Property has not been initialized

Status
Not open for further replies.

MICKI0220

IS-IT--Management
Joined
Jul 20, 2004
Messages
337
Location
US
I get the error in the subject when trying to run the code below. I am new to vb.net and am trying to convert and access database to vb.net. I am trying to bind a form to this query. Any help will be greatly appreciated.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim CN As New SqlConnection
Dim CNstring As String = _
"DATA SOURCE = \\CTIDATA; INITIAL CATALOG = JOBS; " & _
"Integrated Security = True"

CNstring = InputBox( _
"Please enter a Connection String", _
"CONNECTION STRING", CNstring)
If CNstring.Trim = "" Then Exit Sub

Try
CN.Open()
If CN.State = ConnectionState.Open Then
MsgBox("Workstation " & CN.WorkstationID & _
" connected to database " & CN.Database & _
" on the " & CN.DataSource & " server")
End If

Catch ex As Exception
MsgBox( _
"FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR" & _
vbCrLf & ex.Message)

End Try




Dim CMD As New SqlCommand( _
"SELECT tblAccounting.PaymentTerms, tblAccounting.[FIELD PAYROLLS], tblAccounting.[TAX EXEMPT], tblAccounting.[TAX APPLIES], tblCustomer.*, tblEngineerCompany.*, " & _
"tblJobDetails.*, tblJobReqs.*, tblSubcontractDetails.*, tblDatesHours.* " & _
"FROM tblJobCustomerID INNER JOIN " & _
"tblCustomer ON tblJobCustomerID.CustomerID = tblCustomer.CustomerID INNER JOIN " & _
"tblJobDetails ON tblJobCustomerID.JobNoCus = tblJobDetails.JobNo INNER JOIN " & _
"tblDatesHours ON tblJobDetails.JobNo = tblDatesHours.JobNoDH INNER JOIN " & _
"tblAccounting ON tblJobDetails.JobNo = tblAccounting.JobNoAcct INNER JOIN " & _
"tblJobEngineerID ON tblJobDetails.JobNo = tblJobEngineerID.JobNoEng INNER JOIN " & _
"tblEngineerCompany ON tblJobEngineerID.EngineerCompanyID = tblEngineerCompany.EngineerCompanyID INNER JOIN " & _
"tblJobReqs ON tblJobDetails.JobNo = tblJobReqs.JobNoReq CROSS JOIN " & _
"tblSubcontractDetails ", CN)
Dim Count As Integer
CN.Open()
Count = CMD.ExecuteScalar
If CN.State = ConnectionState.Open Then CN.Close()
 
You haven't assigned the CnString to the CN object.
you need something to the effect of:
Code:
Cn.ConnectionString = CnString

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top