■ SQL Server 연결을 구하는 방법을 보여준다.
▶ SQL Server 연결 구하기 예제 (VB)
1 2 3 4 5 |
Dim pConnection As ADODB.Connection Set pConnection = GetSQLServerConnection("127.0.0.1", "testdb", "sa", "1234") |
▶ SQL Server 연결 구하기 (VB)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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 |