以access資料庫為例,Window7
系統,配置數據源,操作步驟如下:
1、打開電腦,點擊開始菜單。
2、打開<控制面板>。
3、在<調整計算機的設置>中,點擊<系統和安全>。
4、點擊<管理工具>。
5、點擊<數據源(ODBC)>。
6、點擊<系統用戶>,然後,點擊按鈕<添加>。
7、在<創建數據源>里,找到Microsoft
Access
Driver(*.mdb),選中.然後點擊完成。
8、在<ODBC
Microsoft
Access
安裝>的<數據源名(N)>,填寫數據有名稱,然後點擊<資料庫>中的<選擇(S)...>。
9、在<選擇資料庫>里,<目錄(D):>里,按路徑找到資料庫文件,選中,點擊確定。回到<ODBC
Microsoft
Access
安裝>點擊確定。最後回到<ODBC數據源管理器>,點擊確定,完成配置。
⑵ 如何新建ODBC並設置系統DSN
DataSourceName =NetmarbleTestDB
DBQPath = NetmarbleTestDB.mdb
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const REG_SZ = 1 'Constant for a string variable type.
Public Const REG_BINARY = 3 'Constant for Binary
Public Const REG_DWORD = 4 '32-bit number
'Creates a Key In Registry
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
'API FOR STRING
Public 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
'API FOR DWORD
Public Declare Function RegSetValueExA Lib "advapi32.dll" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByRef lpData As Long, ByVal cbData As Long) As Long
'API FOR BINARY
Public Declare Function RegSetValueExB Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByRef lpData As Byte, ByVal cbData As Long) As Long
'API for closing the Registry Key
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function GetSystemDirectory Lib "kernel32" Alias _
"GetSystemDirectoryA" (ByVal lpBuffer As String, _
ByVal nSize As Long) As Long
Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Function CreateDSN(DataSourceName As String, DBQPath As String, UID As String, Password As String) As Boolean
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
Dim Engines As String
Dim Jet As String
Dim Driver As String
Dim DriverId As Long
Dim FIL As String
Dim SafeTransaction As Long
Dim ImplicitCommitSync As String
Dim MaxBufferSize As Long
Dim PageTimeOut As Long
Dim Threads As Long
Dim UserCommitSync As String
CreateDSN = True
Engines = "Engines"
Jet = "Jet"
FIL = "MS Access;"
DriverId = &H19
SafeTransaction = &H0
ImplicitCommitSync = ""
MaxBufferSize = &H800
PageTimeOut = &H5
Threads = &H3
Driver = GetSystemPath & "\odbcjt32.dll"
DriverName = "Microsoft Access Driver (*.mdb)"
'Create the new DSN key.
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" & DataSourceName, hKeyHandle)
If lResult <> 0 Then
CreateDSN = False
MsgBox "Write to REG failed, please login as administrator", vbCritical + vbOKOnly
End If
'DBQ
lResult = RegSetValueEx(hKeyHandle, "DBQ", 0&, REG_SZ, ByVal DBQPath, Len(DBQPath))
'Driver
lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, ByVal Driver, Len(Driver))
lResult = RegSetValueExA(hKeyHandle, "DriverId", 0, REG_DWORD, DriverId, 4) 'write the value
'FIL
lResult = RegSetValueEx(hKeyHandle, "FIL", 0&, REG_SZ, ByVal FIL, Len(FIL))
lResult = RegSetValueExA(hKeyHandle, "SafeTransaction", 0, REG_DWORD, SafeTransaction, 4) 'write the value
'Password
lResult = RegSetValueEx(hKeyHandle, "PWD", 0&, REG_SZ, ByVal Password, Len(Password))
'UID
lResult = RegSetValueEx(hKeyHandle, "UID", 0&, REG_SZ, ByVal UID, Len(UID))
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" & DataSourceName & "\" & Engines, hKeyHandle)
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" & DataSourceName & "\" & Engines & "\" & Jet, hKeyHandle)
'ImplicitCommitsync
lResult = RegSetValueEx(hKeyHandle, "ImplicitCommitSync", 0&, REG_SZ, ByVal ImplicitCommitSync, Len(ImplicitCommitSync))
'MaxBufferSize
lResult = RegSetValueExA(hKeyHandle, "MaxBufferSize", 0, REG_DWORD, MaxBufferSize, 4) 'write the value
'PageTimeOut
lResult = RegSetValueExA(hKeyHandle, "PageTimeOut", 0, REG_DWORD, PageTimeOut, 4) 'write the value
'Threads
lResult = RegSetValueExA(hKeyHandle, "Threads", 0, REG_DWORD, Threads, 4) 'write the value
'UserCommitSync
lResult = RegSetValueEx(hKeyHandle, "UserCommitSync", 0&, REG_SZ, ByVal UserCommitSync, Len(UserCommitSync))
'Close the new DSN key.
lResult = RegCloseKey(hKeyHandle)
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 Function
Public Function GetSystemPath() As String
Dim sysPath As String
sysPath = String(255, 0)
Call GetSystemDirectory(sysPath, 256)
sysPath = Left(sysPath, InStr(1, sysPath, Chr(0)) - 1)
GetSystemPath = sysPath
End Function
Public Function GetWindowsPath() As String
Dim sysPath As String
sysPath = String(255, 0)
Call GetWindowsDirectory(sysPath, 256)
sysPath = Left(sysPath, InStr(1, sysPath, Chr(0)) - 1)
GetWindowsPath = sysPath
End Function
⑶ 如何配置ODBC數據源
以WINDOWS XP下配置SQL SERVER的ODBC數據源為例
第一步 在控制面板下選擇 管理工具--ODBC數據源,雙擊圖標
第二步 在用戶DSN 選項卡片上,點「添加」按鈕,出現創建新數據源對話框,選擇SQL Server
第三步 輸入數據源名稱、數據源描述和SQL Server 所在的伺服器名稱或者IP地址。伺服器名稱可以是SQL Server所在的機器名稱,也可以是IP地址。單擊下一步按鈕。
第四步 選擇登錄SQL Server時的身份驗證方式。並輸入登錄SQL Server時所用到的用戶名和密碼。這里的用戶名和密碼是在SQL Server中建立的。
第五步 在更改默認的資料庫填選擇資料庫名,點擊下一步。
第六步,點擊完成,並測試數據源,測試成功後就完成ODBC數據源的創建了。
⑷ 如何用代碼配置ODBC數據源
假如你用的是Access資料庫:控制面板——管理工具——數據源(ODBC)——系統DNS(用戶DNS也可)——添加——Microsoft
Access
Driver
——輸入數據源名稱——找到你的資料庫
這樣就差不多了,如果用的是sql則把DRIVER處換成SQL
SEVRER的就可以了,希望能幫到你,祝好運!
⑸ 如何配置ODBC數據源(以Access資料庫為例)
以access資料庫為例,Window7 系統,配置數據源,操作步驟如下:
1、打開電腦,點擊開始菜單。
⑹ 如何配置資料庫ODBC數據源
1
點擊開始菜單
2
打開<控制面板>.
3
在<調整計算機的設置>中,點擊<系統和安全>.
4
點擊<管理工具>.
5
點擊<數據源(ODBC)>.
6
點擊<系統用戶>,然後,點擊按鈕<添加>.
7
在<創建數據源>里,找到Microsoft Access Driver(*.mdb),選中.然後點擊完成.
8
在<ODBC Microsoft Access 安裝>的<數據源名(N)>,填寫數據有名稱,然後點擊<資料庫>中的<選擇(S)...>
9
在<選擇資料庫>里,<目錄(D):>里,按路徑找到資料庫文件,選中,點擊確定. 回到<ODBC Microsoft Access 安裝>點擊確定.最後回到<ODBC數據源管理器>,點擊確定.完成配置.
⑺ 如何新建odbc
你的意思是怎樣來配置一個ODBC來在編程時應用吧?可以按照下面的步驟做:
1、通過修改注冊表載入數據源:
·用戶數據源:HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI
·系統數據源:HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI
對於不同類型的數據源,注冊表的修改也不同,但基本上要修改兩個地方,一個是在ODBC.INI子鍵下建立一個與數據源描述名同名的子鍵,並在該子鍵下建立與數據源配置相關的項;另一個是在\ODBC.INI\ODBC Data Sources子鍵下建立一個新項以便告訴驅動程序管理器ODBC數據源的類型。
2、通過ODBC API載入:Windows系統子目錄下的動態鏈接庫ODBCinst.dll提供了一個可以動態增加、修改和刪除數據源的函數SQLConfigDataSource,由於VC的默認庫文件中不包含此函數,因此使用前需將ODBCinst.h文件包含在工程的頭文件中,在工程的setting屬性框Link頁的Object/library mole編輯框中增加ODBC32.lib,同時保證系統目錄system32下有文件ODBCcp32.dll。
3、文件數據源的連接:除了ODBC管理器,還可以通過SQLDriverConnect來添加文件數據源。
⑻ win7怎麼配置odbc數據源
win7下ODBC數據源ACCESS2003的鏈接
直接在
控制面板---管理工具----數據源(ODBC)
打開數據源配置,發現只有SQLServer的驅動,其他的都沒有了。
解決方法是:
C:\Windows\SysWOW64
在這個目錄下找到:
odbcad32.exe
這個文件,雙擊打開。
裡面有很多可用個數據源驅動,然後就可用添加連接Access的ODBC的數據源了。