' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.Odbc

Public Class MultiDb
    Public Shared Function GetConnection(ByVal constr As String) As IDbConnection
        If constr.ToUpper.IndexOf("DRIVER=") >= 0 Then
            Return New OdbcConnection (constr)
        Else
            If constr.ToUpper.IndexOf("PROVIDER=") >= 0 Then
                Return New OleDbConnection (constr)
            Else
                If constr.ToUpper.IndexOf("TRUSTED_CONNECTION=") >= 0 OrElse constr.ToUpper.IndexOf("INTEGRATED SECURITY=") >= 0 Then
                    Return New SqlConnection (constr)
                Else
                    Return Nothing
                End If
            End If
        End If
    End Function
End Class 

Class TestClass
    Private Shared Sub test(ByVal constr As String)
        Dim con As IDbConnection = MultiDb.GetConnection(constr)
        con.Open
        Dim cmd As IDbCommand = con.CreateCommand
        cmd.CommandText = "SELECT * FROM T1"
        Dim rdr As IDataReader = cmd.ExecuteReader
        While rdr.Read
            Dim f1 As Integer = CType(rdr(0), Integer)
            Dim f2 As String = CType(rdr(1), String)
            Console.WriteLine(f1 + " " + f2)
        End While
        con.Close
    End Sub

    Public Shared Sub Main(ByVal args As String())
        test("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Database\MSAccess\Test.mdb")
        test("server=ARNEPC2;Integrated Security=SSPI;database=Test")
    End Sub
End Class 
