Hi,
Would it be possible to use my VB.NET project with multiple databases?
I have for example 2 projects, one project with a MSSQL database and another with a SQLite database.
I would like shared classes that can be re-used in both projects,
For example a logging routine (simplified) with a MSSQL database:
Public Shared Sub fLOG(ByVal LUsername As String, ByVal LLogDesc As String, ByVal LProfileNumber As Integer)
Dim cnDestination As New ADODB.Connection()
Dim rsDestination As New ADODB.Recordset()
Dim sSQL As String
Try
cnDestination.ConnectionString = fGetConnectionString()
cnDestination.Open()
sSQL = "INSERT INTO LOG" _
& " (LogDT, LogUserID, LogDesc, LogProfileID)" _
& " VALUES" _
& " (" _
& "'" & Format(System.DateTime.Now, "yyyy-MM-dd HH:m:ss:fff") & "'," _
& "'" & LUsername & "'," _
& "'" & LLogDesc & "'," _
& "'" & LProfileNumber & "'" _
& " )"
cnDestination.Execute(sSQL)
cnDestination.Close()
Catch ex As Exception
MsgBox("Error while logging")
Finally
cnDestination = Nothing
End Try
End Sub
and a second logging routine example with a SQLite database:
Public Sub fLOG(ByVal LUsername As String, ByVal LLogDesc As String, ByVal LProfileNumber As Integer)
Dim cnDestination As New SQLite.SQLiteConnection
Dim daDestination As New SQLite.SQLiteDataAdapter
Dim sqlCommand As New SQLite.SQLiteCommand
Dim sSQL As String
Try
cnDestination.ConnectionString = ConnectionStrings.fGetConnectionString()
cnDestination.Open()
sSQL = "INSERT INTO LOG" _
& " (LogDT, LogUserID, LogDesc, LogProfileID)" _
& " VALUES" _
& " (" _
& "'" & Format(System.DateTime.Now, "yyyy-MM-dd HH:m:ss:fff") & "'," _
& "'" & LUsername & "'," _
& "'" & LLogDesc & "'," _
& "'" & LProfileNumber & "'" _
& " )"
sqlCommand.Connection = cnDestination
sqlCommand.CommandText = sSQL
cnDestination.Close()
Catch ex As Exception
MsgBox("Error while logging")
Finally
cnDestination = Nothing
End Try
End Sub
And the problem I'm having is that the database declaration is done with:
Dim cnDestination As New ADODB.Connection()
Dim rsDestination As New ADODB.Recordset()
and
Dim cnDestination As New SQLite.SQLiteConnection
Dim daDestination As New SQLite.SQLiteDataAdapter
Dim sqlCommand As New SQLite.SQLiteComm
So I need to choose in advance what database I'm going to use.
Who can point me in the direction, in have re-usable code for both projects so I can choose the database during runtime.
Kind regards