ADO .Net Timing Issue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good Morning,

I get the following error when trying to add a record to and access table:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in
system.data.dll. The code runs fine as long as I wait a second or two
between each occurance of it running, but if I try to add the records to fast
the error is generated. I have put a debug.write line at the begining and
end of the code and it is finishing it before the next write starts so does
any one know what the issue is?
Here is my code:


Dim strHolderTN = "'" & strTrailerNumber & "'"
Dim strHolderCN = "'" & strContainerNumber & "'"

Dim strSQL As String = "Insert into tblLotTrace(TrailerKey,
CSerialNumber, DockDoor) values(" & strHolderTN & "," & strHolderCN & "," &
intDoor & ")"
Debug.Write(strSQL)
'Stop
Dim objcommand As New OleDbCommand(strSQL, New
OleDbConnection(gsSQLData))
Debug.Write(objcommand.ToString)
objcommand.Connection.Open()

'Dim cmdLotTrace As OleDbCommand = New OleDbCommand(strSQL,
conLotTrace)
'objcommand.Connection.Open()
objcommand.ExecuteNonQuery()
objcommand.Connection.Close()
objcommand.Dispose()
objcommand = Nothing


Thanks in advance!
 
Dkalsow,

I don't see the problem direct, the best thing you can do is to set your
code in a try and catch block.

The most simple one can be

Dim cmdLotTrace As OleDbCommand = New OleDbCommand(strSQL, conLotTrace)
try
objcommand.Connection.Open()
objcommand.ExecuteNonQuery()
catch ex as oledb.exception
messagebox.show(ex.tostring)
catch ex as exception
messagebox.show(ex.tostring)
finally
objCommand.Connection.dispose
end try

And do not those other closes and setting to nothing, they should not be
needed, maybe is even the error in that, that deep I did not look.

Mostly is done instead of your

Dim conn as new oledbconnection = "connectionstring"
Dim objcommand As New OleDbCommand(strSQL, conn)

And than use instead of your objCommand.Connection

conn.open and conn.dispose.

I think that it is next time better when you ask this question in the
newsgroup

Adonet
news://msnews.microsoft.com/microsoft.public.dotnet.framework.adonet

Web interface:
http://communities2.microsoft.com/c.../?dg=microsoft.public.dotnet.framework.adonet

There is as well the newsgroup
microsoft.public.dotnet.languages.vb

Where this kind of questions are as well done, however the first one it
better for this question.

I hope this helps anyway?

Cor
 
Back
Top