This code will open connection with any kind of database like sql server, MS Access and can make ds
This code will open connection with any kind of database like sql server, MS Access and can make dsn less connection.
Rate This code will open connection with any kind of database like sql server, MS Access and can make ds
(1(1 Vote))
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
This code will open connection with any kind of database like sql server, MS Access and can make ds Comments
No comments yet — be the first to post one!
Post a Comment