I have a vb.net program that I'm converting from compiling in VS2005 to VS2008, and also moving to run on a different server.
This works: vb.net 2005, running on a server with Oracle 10 drivers, writing to Oracle 10g database.
vb.net 2008 compiled as x86, running in debug on my local Win7 machine with Oracle 11 drivers, writing to Oracle 10g database.
This does not work: vb.net 2008 compiled as x86, running on server with Oracle 10 or 11 drivers, writing to Oracle 10g database
The problem is that the program doesn't write anything, but it also doesn't return any errors. It claims that it works fine. The following code does not provide any errors when it runs.
This code sets the connection information (and I just noticed that it does NOT have a try catch here)
Private Sub SetConnectionToDB(ByRef oCMD As OracleCommand)
Dim connectionString As String
connectionString = My.Settings.ImportDataConnectionString
Dim OraDBConnection As OracleConnection
OraDBConnection = New OracleConnection(connectionString)
oCMD.Connection = OraDBConnection
oCMD.CommandType = CommandType.Text
End Sub
and then the following code writes the data. No error occurs here, and after this point, a log is written successfully, so it does go past this point.
EDIT: I added a print to log of the insert command, after the ExecuteNonQuery statement below. It printed to the log the records that I wish would be inserted, if I could only figure out the problem.
Private Sub StoreDataInDB(ByVal insertCommand As String, ByRef oCMD As OracleCommand, ByRef logStream As StreamWriter)
' Connect to the Oracle database and send the insert statement
Try
oCMD.CommandText = insertCommand
oCMD.Connection.Open()
oCMD.ExecuteNonQuery()
Catch ex As Exception
'send error to a log
'MsgBox(ex.Message())
logStream.WriteLine("----------- Error occurred inserting data to Oracle -----------")
logStream.WriteLine(insertCommand)
logStream.WriteLine()
logStream.WriteLine(ex.Message())
logStream.WriteLine()
Finally
oCMD.Connection.Close()
End Try
End Sub
The one thing I'm still unsure about (I'm waiting for a reply), is my connection string. I don't see that my Data Source is identified on my pc, and I'm not sure if it is defined on the servers, or where. My connection string is something like the following:
connectionString="Data Source=OracleDB;User ID=UserIDHere;Password=PasswordHere;Unicode=True;Persist Security Info=True;"
The Insert command is a string of the format
"Insert into user.table (" & _
"FieldName1, " & _
"FieldName2, " & _
"FieldName3) VALUES (" & _
Value1 & ", " & _
Value2 & ", " & _
Value3 & ")"
Are there any ideas for what direction to look, what to try?
EDIT: I've compiled as x86 and x64 (it's a 64 bit server). I've asked for the return value on the oCMD.ExecuteNonQuery and it returns 1 as it pretends to write 1 record. I've messed with the connection string and tried various options. Sometimes it will fail, but when it does work, it still fails silently. The oracle driver on the server is OraClient10g_64.
@BalaR had the right idea -- the connection string is defined in app.config, and I was doing a clean and rebuild. However, there is an autogenerated file in My Project called Settings.Designer.vb, and that is not regenerated on a clean. It had a connection string pointing to a different database.
On my pc, in debug mode or not, it used the settings from app.config. On the server, it used the other connection string, and was writing to a different database.
That autogenerated file needed to be regenerated (double-click My Project, choose Settings tab, and it will rebuild itself), so that it matches the app.config file.