Problem with fast inserting multiple rows into Oracle database from VB

I am trying to insert multiple rows one by one into a database. Here is the relevant code.

Private ConnectionString As String = "Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=xxx)))(CONNECT_DATA=(SID=xxx)(SERVER=DEDICATED)));User Id=xxx;Password=xxx;"
Private SQL As String = "INSERT INTO XXX.BU_LOG (PROGRAM, LOCATION, MESSAGE, TIMESTAMP, ""LEVEL"", COMPUTER, ""USER"") "
Dim Connection As New OleDbConnection(ConnectionString)
Dim Command As OleDbCommand

'The SQL variable is the first part of an insert statement
SQLValues = "VALUES ('" & Program & "','" & Location & "','" & Message & "','" & Timestamp & "','" & LevelName & "','" & Computer & "','" & User & "')"

Dim Command As New OleDbCommand(SQL & SQLValues, Connection)

Connection.Open()
Command.ExecuteNonQuery()
Connection.Close()

      

Now if I call it when it works fine. If I call it twice from different buttons (inserting different values ​​for each button) it works fine. However, when I call the code twice on the same button, one after the other, it inserts two lines, and the second line is the same as the first line. I have checked the command text and it is correct when it does the request, but it is a duplicate line.

If I sleep the thread 500ms before I call the second insert, it works fine. But if I only sleep for 100ms, it gets duplicated. Any ideas?


EDIT: Sorry if I didn't understand. The problem is not with a specific Timestamp column. Actually, everything is fine for the Timestamp column. This is what I call it.

log.Write(My.Application.Info.AssemblyName, System.Reflection.MethodBase.GetCurrentMethod.Name, "Hello World!")
log.Write(My.Application.Info.AssemblyName, System.Reflection.MethodBase.GetCurrentMethod.Name, "Testing", , VB2008_Log_Dll.Log.mLevel.Fatal)

      

As you can see, the first one just writes "Hello World!" and the second one writes "Testing". When I run the program, I get two lines with "Hello World!" Hope this becomes clearer.

+1


source to share


1 answer


What is the datatype of the TIMESTAMP column? If it is a DATE, the Oracle DATE values ​​are only stored to within 1 second, so two inserts in a half second or so will likely have the same value for the column.



There is a newer data type called TIMESTAMP, which is accurate to the fraction of a second, which you can use if needed.

+2


source







All Articles