???? ID: 184608 - ????? ???????: 02 ?????? 2010 - ??????: 4.0

VB ?? ??? SQL ????? ?? ??? ??? 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.

?? ????? ??

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

??????

?? ???? ????????? ???? ?? ?? ????????? SQL Server Visual Basic ?? ????? ???? ?? ??? ??? ???? ????? ?? ??? (DSN) ????? ?? ??? ???? ????? ?? ???? ??? discussed ??????? ????? ?? Windows ????????? ??? ???????????? ?? ????? ?? ??? Windows ????????? ???????????? ??????? (API) ?????? ?? ????? ???? ???

???? ???????

ODBC ???? ????? ?????????? ?????, Windows ???????? ???? (?? Windows 2000 ??? ?????????? ?????) ?? ?????? ?? ???? ?? ????? ?????? ?? DSNs ????? ?? ???? ?? ???? ODBC-?????? ??????? ?? ??? ????? ?????? ???? ???? ???? ??????? ????? RegisterDatabase (??? ???? ????? ???????? (DAO) ??????) ?? ????? ??, SQLConfigDataSource ODBC API ?????? ?? ????? ??, ?? ??? DSN ?? ??????? ???????? ?? ????? ?????

???????, ?? ?? ?? DSN ?? ???????? ??? ?? ????? ?? ??? ?? ?? Windows ????????? ??? ??? ??? ???-??? ?? ?????? ??????? ???? ?? ??? ???? ??? ???? SQL Server ??????? ?? ??? ???? ?????? DSN ????? ?? ??? ????? ??????? RegCreateKey, RegSetValueEx ?? RegCloseKey API ?????? ?? ????? ???? ???

Step-by-Step ????????????

  1. ??? ??? Visual Basic ????????? ?????? Form1 ???????? ??? ?? ???? ??.. Form1 ?? ?? CommandButton ?? ???? (Command1), ?? Form1 ?? ??? ??? ?? ??????? Declarations ??? ??? ????? ??? ????:
        Option Explicit
    
        Private Const REG_SZ = 1    'Constant for a string variable type.
        Private Const HKEY_LOCAL_MACHINE = &H80000002
    
        Private Declare Function RegCreateKey Lib "advapi32.dll" Alias _
           "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, _
           phkResult As Long) As Long
    
        Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias _
           "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
           ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal _
           cbData As Long) As Long
    
        Private Declare Function RegCloseKey Lib "advapi32.dll" _
           (ByVal hKey As Long) As Long
    						
  2. Form1 ?? Command1 ??? ?? ????? ???? ????? ??? ????? ??? ?? ????:

    ???? ?????? ?? ??? ??????? ?? ??? ??? DataSourceName, DatabaseName, ?????, DriverPath, LastUser, ?? ????? ?? ?? ??? ?????? ??? ODBC ???? ????? ?????????? ????? ?? ODBC ??????? ??? ?? ???????? ??????? DriverPath ?? ?? ?? ??? ?? ??? ??? ????? ???? ?? ???? ??? ??? ?? ????????? C:\Windows\System ?? ??? Windows 95 ?? Windows 98 ???? ?? C:\Winnt\System32 ?? ??? Windows NT ??? ????? ?? ???? ???
       Private Sub Command1_Click()
    
       Dim DataSourceName As String
       Dim DatabaseName As String
       Dim Description As String
       Dim DriverPath As String
       Dim DriverName As String
       Dim LastUser As String
       Dim Regional As String
       Dim Server As String
    
       Dim lResult As Long
       Dim hKeyHandle As Long
    
       'Specify the DSN parameters.
    
       DataSourceName = "<the name of your new DSN>"
       DatabaseName = "<name of the database to be accessed by the new DSN>"
       Description = "<a description of the new DSN>"
       DriverPath = "<path to your SQL Server driver>"
       LastUser = "<default user ID of the new DSN>"
       Server = "<name of the server to be accessed by the new DSN>"
       DriverName = "SQL Server"
    
       'Create the new DSN key.
    
       lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" & _
            DataSourceName, hKeyHandle)
    
       'Set the values of the new DSN key.
    
       lResult = RegSetValueEx(hKeyHandle, "Database", 0&, REG_SZ, _
          ByVal DatabaseName, Len(DatabaseName))
       lResult = RegSetValueEx(hKeyHandle, "Description", 0&, REG_SZ, _
          ByVal Description, Len(Description))
       lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, _
          ByVal DriverPath, Len(DriverPath))
       lResult = RegSetValueEx(hKeyHandle, "LastUser", 0&, REG_SZ, _
          ByVal LastUser, Len(LastUser))
       lResult = RegSetValueEx(hKeyHandle, "Server", 0&, REG_SZ, _
          ByVal Server, Len(Server))
    
       'Close the new DSN key.
    
       lResult = RegCloseKey(hKeyHandle)
    
       'Open ODBC Data Sources key to list the new DSN in the ODBC Manager.
       'Specify the new value.
       'Close the key.
    
       lResult = RegCreateKey(HKEY_LOCAL_MACHINE, _
          "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", hKeyHandle)
       lResult = RegSetValueEx(hKeyHandle, DataSourceName, 0&, REG_SZ, _
          ByVal DriverName, Len(DriverName))
       lResult = RegCloseKey(hKeyHandle)
    
       End Sub
    						
  3. ????????? ?? ?????, ?? Command1 ???? ??? ?? ????? ????? ???? ??? ???????? ???? (?? Windows 2000 ??? ?????????? ?????) ?? ODBC ???? ????? ?????????? ??? ?????? ???? ?????? ???? ?? ???? ?? DSNs ?? ??? ???? ??? DSN ????????

??????

???????? ??????? ?? ???, ????? ????? ?????? ?? Microsoft ???????? ??? ?????:
166392  (http://support.microsoft.com/kb/166392/EN-US/ ) RDO ?? ??? "DSN-??" ODBC ??????? ?? ????? ???? ????
147875  (http://support.microsoft.com/kb/147875/EN-US/ ) RDO ?? DAO ?? ??? "DSN-??" ODBC ??????? ?? ????? ???? ????
171146  (http://support.microsoft.com/kb/171146/EN-US/ ) ???? ????? ?? Visual Basic ??? ?? DSN ???????
123008  (http://support.microsoft.com/kb/123008/EN-US/ ) ??? ?? ODBC ???? ????? ?? ??? Distributing ???? ????

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