Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL"(Byval hwndParent As Long,Byval fRequest As Long,Byval lpszDriver As String,Byval lpszAttributes As String) As Long
Private Const ODBC_ADD_DSN = 1
Private Const ODBC_CONFIG_DSN = 2
Private Const ODBC_REMOVE_DSN = 3
Private Const ODBC_ADD_SYS_DSN = 4
Private Const ODBC_REMOVE_SYS_DSN = 6
Private Const lhyApi = 0&
Class ODBC_Class
Sub new()
End Sub
Public
Function CreateDSN (sDSN As String,serverName As String ,dbName As String) As Integer
On Error Resume Next
Dim nRet As Long
Dim sDriver As String
Dim sAttributes As String
sDriver = "SQL server"
sAttributes = "DSN=" & sDSN & Chr(0)
sAttributes = sAttributes & "Server=" & serverName & Chr(0)
sAttributes = sAttributes & "Database=" & dbName & Chr(0)
nRet = SQLConfigDataSource(lhyApi,ODBC_ADD_SYS_DSN,sDriver,sAttributes)
If nRet <> 1 Then
CreateDSN = False
Else
CreateDSN = True
End If
End Function
Public Function DeleteDSN(sDSN As String) As Integer
On Error Resume Next
Dim nRet As String
Dim sDriver As String
Dim sAttributes As String
sDriver = "SQL server"
sAttributes = "DSN=" & sDSN & Chr(0)
nRet = SQLConfigDataSource(lhyApi , ODBC_REMOVE_SYS_DSN,sDriver,sAttributes)
If nRet <> 1 Then
DeleteDSN = False
Else
DeleteDSN = True
End If
End Function
End Class
Private Const ODBC_ADD_DSN = 1
Private Const ODBC_CONFIG_DSN = 2
Private Const ODBC_REMOVE_DSN = 3
Private Const ODBC_ADD_SYS_DSN = 4
Private Const ODBC_REMOVE_SYS_DSN = 6
Private Const lhyApi = 0&
Class ODBC_Class
End Class