by Kamlesh Santani (5 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Wed 20th September 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This code will open connection with any kind of database like sql server, MS Access and can make dsn less connection.
sqlserver
MSAccess
ODBCAccess
ODBCSql
End Enum
Public Function OpenConnection(cnGeneral As ADODB.Connection, Provider As BackEnd, database As String, Optional user As String, Optional pwd As String, Optional dsnName As String)
Set cnGeneral = New ADODB.Connection
Dim X As String
If Provider = sqlserver Then
X = "sqloledb.1"
cnGeneral.Open "Provider= '" & X & "'" & ";Persist Security Info=True;User ID= '" & user & "'" & ";Password= '" & pwd & "'" & ";Initial Catalog= '" & database & "'" & ";Data Source=131.107.2.109;Connect Timeout=0"
ElseIf Provider = MSAccess Then
X = "Microsoft.Jet.OLEDB.4.0"
cnGeneral.Open "Provider= '" & X & "'" & ";Persist Security Info=False;Data Source= '" & database & "'"
ElseIf Provider = ODBCAccess Then
X = "MSDASQL.1"
cnGeneral.Open "Provider= '" & X & "'" & ";Persist Security Info=False;Data Source= '" & dsnName & "'" & ";Connect Timeout=0;Initial Catalog= '" & database & "'"
ElseIf Provider = ODBCSql Then
X = "MSDASQL.1"
cnGeneral.Open "Provider= '" & X & "'" & ";Password= '" & pwd & "'" & ";Persist Security Info=True;User ID= '" & user & "'" & ";Data Source= '" & dsnName & "'" & ";Connect Timeout=0;Initial Catalog= '" & database & "'"
End If
Exit Function
End Function
No comments have been posted about This code will open connection with any kind of database like sql server, MS Access and can make ds. Why not be the first to post a comment about This code will open connection with any kind of database like sql server, MS Access and can make ds.