■ SQL Server 연결 구하기 예제

----------------------------------------------------------------------------------------------------

Dim pConnection As ADODB.Connection

 

Set pConnection = GetSQLServerConnection("127.0.0.1", "testdb", "sa", "1234")

----------------------------------------------------------------------------------------------------

 

■ SQL Server 연결 구하기

----------------------------------------------------------------------------------------------------

Public Function GetSQLServerConnection(strDataSource As String, strInitialCatalog As String, strUserID As String, strPassword As String) As ADODB.Connection

    

    Dim pConnection         As ADODB.Connection

    Dim strConnectionString As String

    

    Set GetSQLServerConnection = Nothing

    

    On Error GoTo ErrorLabel

    

    Set pConnection = New ADODB.Connection

 

    strConnectionString = "Provider=SQLOLEDB.1;Data Source=" + strDataSource + ";Initial Catalog=" + strInitialCatalog + ";User ID=" + strUserID + ";Password=" + strPassword + ";Persist Security Info=True"

    

    pConnection.Open strConnectionString

    

    On Error GoTo 0

 

    Set GetSQLServerConnection = pConnection

    

    Exit Function

 

ErrorLabel:

    

End Function

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요