본문 바로가기
Application/VB Lecture

ODBC DSN 자동 생성

by 현이빈이 2008. 8. 13.
반응형

Option Explicit
Private Const ODBC_ADD_DSN As Long = 1
Private Const ODBC_ADD_SYS_DSN As Long = 4
Private Const ODBC_BOTH_DSN As Long = 0
Private Const ODBC_CONFIG_DRIVER As Long = 3
Private Const ODBC_CONFIG_DSN As Long = 2
Private Const ODBC_CONFIG_SYS_DSN As Long = 5
Private Const ODBC_REMOVE_DSN As Long = 3
Private Const ODBC_REMOVE_SYS_DSN As Long = 6
Private Const ODBC_SYSTEM_DSN As Long = 2
Private Const ODBC_USER_DSN As Long = 1
Private Const SQL_DRIVER_COMPLETE As Long = 1
Private Const SQL_DRIVER_COMPLETE_REQUIRED As Long = 3


Private Declare Function SQLConfigDataSource Lib "odbccp32.dll" (ByVal hwndParent As Long, ByVal fRequest As Integer, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long

'DSN 자동 생성

Private Sub cmdCreateDSN_Click()
'Create DSN With ODBC API
    Dim cOra As Long
    Dim sDrv As String
    Dim sAttr As String
    sDrv = "Microsoft ODBC For ORACLE"
    sAttr = "DSN=TEST_ORACLE" & Chr(0)
    sAttr = sAttr & "Description=Temporary DSN For ORACLE" & Chr(0)
    sAttr = sAttr & "SERVER=SCOTT"
    cOra = SQLConfigDataSource(Me.hWnd, ODBC_ADD_DSN, sDrv, sAttr)
    If cOra = 1 Then
        MsgBox "Create DSN Successfully", vbInformation
        cmdRemDSN.Enabled = True
    Else
        MsgBox "Create DSN Failed", vbCritical
    End If
End Sub


'DSN 삭제

Private Sub cmdRemDSN_Click()
'Remove DSN With ODBC API
    Dim cOra As Long
    Dim sDrv As String
    Dim sAttr As String
    sDrv = "Microsoft ODBC For ORACLE"
    sAttr = "DSN=TEST_ORACLE" & Chr(0)
    sAttr = sAttr & "Description=Temporary DSN For ORACLE" & Chr(0)
    sAttr = sAttr & "SERVER=SCOTT"
    cOra = SQLConfigDataSource(Me.hWnd, ODBC_REMOVE_DSN, sDrv, sAttr)
    If cOra = 1 Then
        MsgBox "Remove DSN Successfully", vbInformation
        cmdRemDSN.Enabled = False
    Else
        MsgBox "Failed To Remove DSN", vbCritical
    End If
End Sub

반응형