■ SQL Server 연결 구하기 (윈도우즈 인증) 예제

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

Dim pConnection As ADODB.Connection

 

Set pConnection = GetSQLServerConnectionWithWindowsAuthentication("127.0.0.1", "testdb")

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

 

■ SQL Server 연결 구하기 (윈도우즈 인증)

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

Public Function GetSQLServerConnectionWithWindowsAuthentication(strDataSource As String, strInitialCatalog As String) As ADODB.Connection

    

    Dim pConnection         As ADODB.Connection

    Dim strConnectionString As String

    

    Set GetSQLServerConnectionWithWindowsAuthentication = Nothing

    

    On Error GoTo ErrorLabel

    

    Set pConnection = New ADODB.Connection

 

    strConnectionString = "Provider=SQLOLEDB.1;Data Source=" + strDataSource + ";Initial Catalog=" + strInitialCatalog + ";Integrated Security=SSPI;Persist Security Info=False"

    

    pConnection.Open strConnectionString

    

    On Error GoTo 0

 

    Set GetSQLServerConnectionWithWindowsAuthentication = pConnection

    

    Exit Function

 

ErrorLabel:

    

End Function

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

Posted by 사용자 icodebroker

댓글을 달아 주세요