???? ID: 171146 - ????? ???????: 02 ?????? 2010 - ??????: 4.0

???? ????? ?? Visual Basic ??? ?? DSN ???????

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????

??????

Visual Basic 4.0 ?? 32-??? ???????, ??-DSN ??????? ?? ????? ???? ???? ??, ????? ODBC ?? 16-??? ??????? ?? ???????? ?? ????? ???? ?? ????, ??????? ?? ???? ???? ?? Visual Basic 4.0 ?? 16-??? ??????? ??? ??? ???? ?? ???? ?? ?????? ??? ?? ????? ?? ??? ?? ?? ??? ???? ????? ?? ??? (DSN) ????? SQLConfigDataSource ODBC API ??? ?? ????? ?? ??? ?? ?? ??????? ?? ?????? ?? ?? ?????? ???? ???? ???

????? ?? ??? 16- ?? ?? ????? ????????? ???? ?? ?? 32-??? ??????? ??????? ?? ????? ?? ???? ????? ???? ???? ?????? 32-??? ??? ????? ??? 32-??? ??????? ?? ?? ???? ??? ???????? ??? ?? Visual Basic 5.0 ???? ?? ??? ?? ???? ?????

???? ???????

??? DSN ?? ??????? ?? ????? ???? ?? ??? 32-??? ODBC ?????? ??? ?? ????? ??:
  1. ??????? Simplicity. ???? DSN ??? ??, ??? ?? ??????, ??????, ??? ??? ???? ?? ???? ??? ????? ???? ?? ??? ?????????? ???? ??? ??? ?? ?? ???? ?? ??? ?????? ??? ?? ????????? ???????
  2. ?? JET ???? ?? ?? ??????? solves ?? ???????? ?? ??? ???????? ?????? ?????
  3. ????????? ?? ??? ?? ?????? ???
??? ?? ????? ?? ???? ?? realized 16-??? ODBC ??? ??? ??? ?? ?? ?? DSN ????? ?? ????? ?? ??? ??? ?? ???? ?? ?????? DSN ??????? ?? ??? ?????? ??? ???????? ??? ?? ?????, ??????, ?? ????? ?? ??? ??? DSN ???? ?? ??? ??? ?? ????? ???? ?? ???? Visual Basic ?? DSN DBEngine.RegisterDatabase() ???? ????? ?? ?????? ?????? ????? ??, ????? API ???? ??????????? ?? ??????? ???? ?? ???? DSN, ??? ?? ??????? ?? ?????? ???? ???

Step-by-Step ??????

  1. ??? ??? ????????? ??????? ?????
  2. ' ????? ' ???? ?? ??????? ?????? ????? ????? ?? ????? ???, ??? ?? ????? Compilation ???? ?? ????? ?? Visual Basic 4.0 32-???, ?? 0 ??? Visual Basic 4.0 16-??? ?? ????? ???? ??? ??? WIN32 1 ?? ????? ?? ??? ??? ?????
  3. ???????? ??? ?? ?? CommandButtons ???????
  4. ??????? Declarations ???? ?? ??? ????? ??? ??????:
          Option Explicit
    
          'Constant Declaration
          Private Const ODBC_ADD_DSN = 1        ' Add data source
          Private Const ODBC_CONFIG_DSN = 2     ' Configure (edit) data source
          Private Const ODBC_REMOVE_DSN = 3     ' Remove data source
          Private Const vbAPINull As Long = 0&  ' NULL Pointer
    
          'Function Declare
          #If WIN32 Then
    
              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
          #Else
              Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" _
              (ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal _
              lpszDriver As String, ByVal lpszAttributes As String) As Integer
          #End If
    					
  5. Command1 ?? ????? ????? ??? ????? ??? ?? ??????:
          #If WIN32 Then
              Dim intRet As Long
          #Else
              Dim intRet As Integer
          #End If
          Dim strDriver As String
          Dim strAttributes As String
    
          'Set the driver to SQL Server because it is most common.
          strDriver = "SQL Server"
          'Set the attributes delimited by null.
          'See driver documentation for a complete
          'list of supported attributes.
          strAttributes = "SERVER=SomeServer" & Chr$(0)
          strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
          strAttributes = strAttributes & "DSN=DSN_TEMP" & Chr$(0)
          strAttributes = strAttributes & "DATABASE=pubs" & Chr$(0)
          'To show dialog, use Form1.Hwnd instead of vbAPINull.
          intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
          strDriver, strAttributes)
          If intRet Then
              MsgBox "DSN Created"
          Else
              MsgBox "Create Failed"
          End If
    					
  6. Command2 ?? ????? ????? ??? ????? ??? ?? ??????:
          #If WIN32 Then
              Dim intRet As Long
          #Else
              Dim intRet As Integer
          #End If
          Dim strDriver As String
          Dim strAttributes As String
    
          'Set the driver to SQL Server because most common.
          strDriver = "SQL Server"
          'Set the attributes delimited by null.
          'See driver documentation for a complete list of attributes.
          strAttributes = "DSN=DSN_TEMP" & Chr$(0)
          'To show dialog, use Form1.Hwnd instead of vbAPINull.
          intRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, _
          strDriver, strAttributes)
          If intRet Then
              MsgBox "DSN Deleted"
          Else
              MsgBox "Delete Failed"
          End If
    					
  7. ????????? ?? ??????
  8. Command1 ?? DSN DSN_TEMP ??? ????? ?? ??? ????? ?????
  9. Command2 DSN DSN_TEMP ??? ??????? ?? ??? ????? ?????

??????

ODBC 2.0 ?????????? ?? ?????? ?? SDK ????????????
Microsoft ????? 1993
ISBN 1-55615-658-8

(?) Microsoft Corporation 1997, ??? ?????? ????????? ???????? ?? Troy Cambra, Microsoft Corporation ?? ??????

???? ???? ???? ??:
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 4.0 Enterprise Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
??????: 
kbhowto kbmt KB171146 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:171146  (http://support.microsoft.com/kb/171146/en-us/ )