用API函数建立ODBC??????

lxp1314yzp 2002-06-11 04:10:56
我想在form_load事件中调用API 函数来直接建ODBC,以免用户还要手动建!!!!
有哪位高能帮在下!!!!!!!!!在线等待!!
...全文
34 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lirun 2002-06-11
  • 打赏
  • 举报
回复
同意
small_wolf 2002-06-11
  • 打赏
  • 举报
回复
’用ODBC API函数SQLConfigDataSource

'声明
Private Const ODBC_ADD_DSN = 1 ' Add user data source
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) user data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove user data source
Private Const ODBC_ADD_SYS_DSN = 4 'Add sys data source
Private Const ODBC_REMOVE_SYS_DSN = 6 'Remove sys data source
Private Const vbAPINull As Long = 0& ' NULL Pointer
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

'ACCESS数据库

strDriver = "Microsoft Access Driver (*.mdb)"
strAttributes = ""
strAttributes = strAttributes & "DSN=MGCP" & Chr$(0)
strAttributes = strAttributes & "FIL=MS Access" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=TempDSN" & Chr$(0)
strAttributes = strAttributes & "DBQ=" & SetupWebDir & "\Adm\MSU\msu\msu_config.mdb" & Chr$(0)
strAttributes = strAttributes & "DefaultDir=" & SetupWebDir & "\Adm\MSU\msu\" & Chr$(0) & Chr$(0)
'如果要显示对话,可使用 Form1.Hwnd 代替 vbAPINull.
intRet = SQLConfigDataSource(vbAPINull, 4, strDriver, strAttributes)
If intRet Then
Else
MsgBox "建立系统ODBC数据源出错,请确认安装了ODBC For Access驱动程序!", vbOKOnly + vbExclamation, titODBCError
End If


'以下为SQL SERVER的ODBC数据源,注意UID和PWD不能写,否则会出错
strAttributes = ""
strAttributes = strAttributes & "DSN=MGCP" & Chr$(0)
'strAttributes = strAttributes & "UID=sa" & Chr$(0)
'strAttributes = strAttributes & "PWD=123" & Chr$(0)
strAttributes = strAttributes & "SERVER=" & DBServer & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=MGCP DSN" & Chr$(0)
strAttributes = strAttributes & "DATABASE=msu_config" & Chr$(0) & Chr$(0)
'如果要显示对话,可使用 Form1.Hwnd 代替 vbAPINull.
intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_SYS_DSN, strDriver, strAttributes)
If intRet Then
Else
MsgBox msgODBCError, vbOKOnly + vbExclamation, titODBCError
End If
孙小雄 2002-06-11
  • 打赏
  • 举报
回复
http://www.csdn.net/Expert/TopicView1.asp?id=777670
孙小雄 2002-06-11
  • 打赏
  • 举报
回复

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
不规则窗口的建立(字体窗体) 在Delphi中自动检测、建立数据库别名和表格 用Delphi制作留言板 用DEPHI 3.0实现动画ABOUT窗口 在DELPHI中处理时间 如何为Delphi程序添加事件和事件处理器 在DELPHI程序中使用ADO对象存取ODBC数据库 轻轻松松在DELPHI3.0中实现三态按钮 Api函数列表【与文件有关】 Api函数列表【与打印有关】 Delphi中TApplication类的巧用 Delphi 中自做动态显示的控件 DELPHI 中 自 适 应 表 单 的 实 现 在Delphi 中 利 用 Tbatch 组 件 如何在注册表中注册BDE 如何在标题栏上增加按钮 CGI技术及其开发(一) CGI技术及其开发(二) 用Delphi实现壁纸更换 在Delphi中获取和修改文件的时间 任何动态改变/添加网络设置中的 TCP/IP 的 DNS 地址 让彩色光标出现在Delphi程序中 面向组件的系统开发方法 COM/DCOM中如何传递数组 COM/DCOM的区别与联系 定制Delphi应用程序的系统菜单 Delphi 3中Cookie的建立使用 一 个 实 用 的Delphi 屏 幕 拷 贝 程 序 的 设 计 用Delphi制作动态菜单 用Delphi进行OpenGL编程学习心得 开 发 基 于ORACLE7 数 据 库 的 管 理 信 息 系 统 用Delphi 实 现 自 定 义 颜 色 对 话 框 及 其 构 件 Delphi自定义消息应用一例 自 定 义 快 速 报 表 的 打 印 预 览 窗 口 如何把文件删除到回收站中 在Delphi与C 之间实现函数与对象共享 编 译 错 误 信 息 DELPHI AND THE INTERNET by Charlie Calvert [1] DELPHI AND THE INTERNET by Charlie Calvert [2] Delphi之快速设计(程序设计篇) Delphi之快速设计(界面设计篇) 在DELPHI2.0/3.0中直接操作端口 开 发AS/400 应 用 系 统: PB5 与Delphi3 的 比 较 检查驱动器是否就绪 在Delphi应用程序中拖动控件 用修改文件时间的方法来加密文件 资 源 文 件 在DELPHI 中 的 使 用 怎样建立简单的任务栏应用程序 控 制 系 统 菜 单 用Dephi 程 序 维 护Paradox 数 据 表 的 索 引 用Delphi实现无边界窗体的移动 Delphi函数参考手册

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧