如何动态新增移除ODBC,DSN? MSDN中有源代码,还是中文的,就是可视化数据管理器,里面有这个功能的,你可以参考里面的源代码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以查看WINDOWS注册表中ODBC的存储方式ODBC的配置在注册表中保存的 引用 ODBC Driver & Data Source Name FunctionsDim xx As New ODBCTool.Dsnxx.CreateDSN ... 动态新增、移除ODBC DSN一般我们建立 Client 端 DSN 都是在使用者的机器上进入【控制台】【ODBC 资料来源管理员】去建立,但是如果我们开发的 APP 使用者很多时,这就有点累人了,所以我们可以将这个动作放在程序中!新增 DSN 的方法有二种:1、使用 DBEngine 物件的 RegisterDatabase 方法2、呼叫 SQLConfigDataSource API不管使用以上任何一种方法新增 DSN,一共会写入二个地方,一个是注册表,一个是 ODBC.INI。而删除 DSN 的方法同上面的第二种方法,呼叫 SQLConfigDataSource API。以下之模组以 Oracle73 Ver 2.5 为例,在 Form 的声明区中加入以下声明及模组:Private Const ODBC_ADD_DSN = 1 ′ Add data sourcePrivate Const ODBC_CONFIG_DSN = 2 ′ Configure (edit) data sourcePrivate Const ODBC_REMOVE_DSN = 3 ′ Remove data sourcePrivate Const vbAPINull As Long = 0& ′ NULL PointerPrivate Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _(ByVal hwndParent As Long, ByVal fRequest As Long, _ByVal lpszDriver As String, ByVal lpszAttributes As String) As LongPublic Sub CreateDSN(sDSN As String)Dim nRet As LongDim sDriver As StringDim sAttributes As StringsDriver = "Oracle73 Ver 2.5"sAttributes = "Server=Oracle8" & Chr$(0)sAttributes = sAttributes & "DESCRIPTION=" & sDSN & Chr$(0)′sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)sAttributes = sAttributes & "DATABASE=DBFinance" & Chr$(0)sAttributes = sAttributes & "Userid=Scott" & Chr$(0)′sAttributes = sAttributes & "PWD=myPassword" & Chr$(0)DBEngine.RegisterDatabase sDSN, sDriver, True, sAttributes ′注一′nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, sDriver, sAttributes) ′注二End SubPublic Sub DeleteDSN(sDSN As String)Dim nRet As LongDim sDriver As StringDim sAttributes As StringsDriver = "Oracle73 Ver 2.5"sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)nRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, sDriver, sAttributes)End Sub′假设要产生的 DSN 为 Test,实际使用范例如下:Private Sub Command1_Click()CreateDSN "Test"End SubPrivate Sub Command2_Click()DeleteDSN "Test"End Sub′而写到系统的资料如下:1、ODBC.INI[ODBC 32 bit Data Sources]Test=Oracle73 Ver 2.5 (32 bit)[Test]Driver32=C:\ORAWIN95\ODBC250\sqo32_73.dll2、注册表机码:HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC Data Sources名称:Test 资料:Oracle73 Ver 2.5机码:HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\Test名称:Description 资料:Test名称:Driver 资料:C:\ORAWIN95\ODBC250\sqo32_73.dll名称:Server 资料:Oracle8名称:UserId 资料:Scott※注一及注二可任选一种,只要将不使用的方法 Mark 起来即可!※若您想使用其他之资料库,只要将以上模组稍作修改即可! 以上代码来自: SourceCode Explorer(源代码数据库) 复制时间: 2002-06-24 20:49:47 当前版本: 1.0.714 作者: Shawls 个人主页: Http://Shawls.Yeah.Net E-Mail: [email protected] QQ: 9181729 请问有没在工作的 VB 碰到个奇怪的问题,纳闷了一下午。 mshflexgrid 收缩和展开实例,跪求!! 怎样可以使datacombo控件自动下拉列表? 200分 求 IC OR ID 简单门禁系统 源代码 Oracle和VB的问题(问题比较多,见笑了) ?如何让窗体时时透明? 有些怪异的现象,请高人指点一下。 如何能够捕捉到访问光驱或软驱的事件,操作系统高手请进 通过VB将图象保存到数据库方法优劣的讨论 急急急死我了,请大家一定认真看一下我的问题!!!!! 条形码打印源代玛 1000分
ODBC的配置在注册表中保存的
xx.CreateDSN ...
1、使用 DBEngine 物件的 RegisterDatabase 方法
2、呼叫 SQLConfigDataSource API不管使用以上任何一种方法新增 DSN,一共会写入二个地方,一个是注册表,一个是 ODBC.INI。而删除 DSN 的方法同上面的第二种方法,呼叫 SQLConfigDataSource API。以下之模组以 Oracle73 Ver 2.5 为例,在 Form 的声明区中加入以下声明及模组: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 PointerPrivate Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) As LongPublic Sub CreateDSN(sDSN As String)
Dim nRet As Long
Dim sDriver As String
Dim sAttributes As String
sDriver = "Oracle73 Ver 2.5"
sAttributes = "Server=Oracle8" & Chr$(0)
sAttributes = sAttributes & "DESCRIPTION=" & sDSN & Chr$(0)
′sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
sAttributes = sAttributes & "DATABASE=DBFinance" & Chr$(0)
sAttributes = sAttributes & "Userid=Scott" & Chr$(0)
′sAttributes = sAttributes & "PWD=myPassword" & Chr$(0)
DBEngine.RegisterDatabase sDSN, sDriver, True, sAttributes ′注一
′nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, sDriver, sAttributes) ′注二
End SubPublic Sub DeleteDSN(sDSN As String)
Dim nRet As Long
Dim sDriver As String
Dim sAttributes As String
sDriver = "Oracle73 Ver 2.5"
sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
nRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, sDriver, sAttributes)
End Sub′假设要产生的 DSN 为 Test,实际使用范例如下:Private Sub Command1_Click()
CreateDSN "Test"
End SubPrivate Sub Command2_Click()
DeleteDSN "Test"
End Sub′而写到系统的资料如下:1、ODBC.INI[ODBC 32 bit Data Sources]
Test=Oracle73 Ver 2.5 (32 bit)[Test]
Driver32=C:\ORAWIN95\ODBC250\sqo32_73.dll2、注册表机码:HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC Data Sources
名称:Test 资料:Oracle73 Ver 2.5机码:HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\Test
名称:Description 资料:Test
名称:Driver 资料:C:\ORAWIN95\ODBC250\sqo32_73.dll
名称:Server 资料:Oracle8
名称:UserId 资料:Scott※注一及注二可任选一种,只要将不使用的方法 Mark 起来即可!
※若您想使用其他之资料库,只要将以上模组稍作修改即可!
以上代码来自: SourceCode Explorer(源代码数据库)
复制时间: 2002-06-24 20:49:47
当前版本: 1.0.714
作者: Shawls
个人主页: Http://Shawls.Yeah.Net
E-Mail: [email protected]
QQ: 9181729