J
Joshua Campbell
I just wrote a piece of code to insert into a SQL database. Sometimes it
works, sometimes it errors out with "The ConnectionString property has not
been initialized". I can not figure out why it is diong this. Can someone
please help me figure out what is wrong? Here is the code:
==================
Dim objAck As DataView = MyView1
Dim AckView As DataRowView
Dim strRev, strWLMOrderNum, strCustOrderNum, strSoldTo, strShipTo,
strOrderDate As String
Try
For Each AckView In objAck
strWLMOrderNum = AckView("OurOrderNo")
strRev = AckView("Rev")
strCustOrderNum = AckView("CustOrderNo")
strOrderDate = AckView("OrderDate")
strOrderDate = strOrderDate.Replace("-", "/")
strSoldTo = AckView("SoldToNo")
strShipTo = AckView("ShipToNo")
Next
If strRev = "" Then
Dim queryCommand As New SqlClient.SqlCommand
queryCommand.CommandType = CommandType.Text
queryCommand.Connection = SqlConnection1
queryCommand.Connection.Open()
queryCommand.CommandText = "INSERT INTO OrderAck (SoldTo,
ShipTo, OrderDate, WLMOrderNum, CustOrderNum) VALUES ('" _
& strSoldTo & "', '" & strShipTo & "', '" & strOrderDate & "', '" &
strWLMOrderNum & "', '" & strCustOrderNum & "')"
queryCommand.ExecuteNonQuery()
queryCommand.Connection.Close()
queryCommand.Connection.Dispose()
queryCommand = Nothing
End If
Catch x As Exception
EventLog.WriteEntry("OrderAck to PDF Application", "There was an
error in UploadToSQL." & vbCrLf & x.Source & vbCrLf & x.Message,
EventLogEntryType.Error, 1, 1)
End Try
==================
x.Source is coming back with "System.Data" and x.Message is stating "The
ConnectionString property has not been initialized.".
Please help me. Could it be that during the first pass, this works, but the
dispose gets rid of the values in my SqlConnection1 for the other passes?
Thanks.
Joshua
works, sometimes it errors out with "The ConnectionString property has not
been initialized". I can not figure out why it is diong this. Can someone
please help me figure out what is wrong? Here is the code:
==================
Dim objAck As DataView = MyView1
Dim AckView As DataRowView
Dim strRev, strWLMOrderNum, strCustOrderNum, strSoldTo, strShipTo,
strOrderDate As String
Try
For Each AckView In objAck
strWLMOrderNum = AckView("OurOrderNo")
strRev = AckView("Rev")
strCustOrderNum = AckView("CustOrderNo")
strOrderDate = AckView("OrderDate")
strOrderDate = strOrderDate.Replace("-", "/")
strSoldTo = AckView("SoldToNo")
strShipTo = AckView("ShipToNo")
Next
If strRev = "" Then
Dim queryCommand As New SqlClient.SqlCommand
queryCommand.CommandType = CommandType.Text
queryCommand.Connection = SqlConnection1
queryCommand.Connection.Open()
queryCommand.CommandText = "INSERT INTO OrderAck (SoldTo,
ShipTo, OrderDate, WLMOrderNum, CustOrderNum) VALUES ('" _
& strSoldTo & "', '" & strShipTo & "', '" & strOrderDate & "', '" &
strWLMOrderNum & "', '" & strCustOrderNum & "')"
queryCommand.ExecuteNonQuery()
queryCommand.Connection.Close()
queryCommand.Connection.Dispose()
queryCommand = Nothing
End If
Catch x As Exception
EventLog.WriteEntry("OrderAck to PDF Application", "There was an
error in UploadToSQL." & vbCrLf & x.Source & vbCrLf & x.Message,
EventLogEntryType.Error, 1, 1)
End Try
==================
x.Source is coming back with "System.Data" and x.Message is stating "The
ConnectionString property has not been initialized.".
Please help me. Could it be that during the first pass, this works, but the
dispose gets rid of the values in my SqlConnection1 for the other passes?
Thanks.
Joshua