'sqlserver DSN 删除 舔加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 vbAPINull As Long = 0&
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal hwndParent As Long, ByVal fRequest As Long, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long
Public Sub CreateDSN(sDSN As String)
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=(local)" & Chr$(0)
sAttributes = sAttributes & "Database=webstation" & Chr$(0)
nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_SYS_DSN, sDriver, sAttributes)
End Sub
Public Sub DeleteDSN(sDSN As String)
On Error Resume Next
Dim nRet As Long
Dim sDriver As String
Dim sAttributes As String
sDriver = "SQl server"
sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
nRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_SYS_DSN, sDriver, sAttributes)
End Sub
Private Sub Command1_Click()
CreateDSN "Test"
End Sub
Private Sub Command2_Click()
DeleteDSN "Test"
End Sub