VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code will open connection with any kind of database like sql server, MS Access and can make ds

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.

Rate This code will open connection with any kind of database like sql server, MS Access and can make ds



    
    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



Download this snippet    Add to My Saved Code

This code will open connection with any kind of database like sql server, MS Access and can make ds Comments

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.

Post your comment

Subject:
Message:
0/1000 characters