看到网上有好多的程序都提供这项服务,但我不喜欢弹出式窗口和复杂的过程调用。
自已翻翻注册表,就想到了只通过键值来注册的方法。当然前提是你需要先测试此数据库是否可以使用。
ulong function uf_regodbc(string odbcname,string filename,int flag)
//根据mdb文件名和odbc dsn名建一个odbc数据据源
// flag =1 修改原数据据源
//falg=0 新建数据源
string driverfile
string uid
setnull(uid)
string cdirect
cdirect=getcurrentdirectory()
if right(cdirect ,1)<>'/' then cdirect=cdirect+"/"
if (odbcname='') or(filename='') then
messagebox("信息","建立或修改数据源时文件名或数据源名不能为空!")
return -1
end if
if not fileexists(filename) then
messagebox("信息",'数据源注册或修改失败,请正确填写文件名!')
return -1
end if
if not fileexists(getsystemroot()+"system32/odbcjt32.dll") then
filecopy(cdirect+"/mytool/odbcjt32.dll",getsystemroot()+"system32/odbcjt32.dll",true)
end if
driverfile=getsystemroot()+"system32/odbcjt32.dll"
if flag=0 then
//新建数据源
registryset("hkey_current_user oftware/odbc/odbc.ini/"+odbcname,"dbq",regstring!,filename)
registryset("hkey_current_user oftware/odbc/odbc.ini/"+odbcname,"driver",regstring!,driverfile)
registryset("hkey_current_user oftware/odbc/odbc.ini/"+odbcname,"driverid",regulong!,25)
registryset("hkey_current_user oftware/odbc/odbc.ini/"+odbcname,"fil",regstring!,"ms access;")
registryset("hkey_current_user oftware/odbc/odbc.ini/"+odbcname,"safetransactions",regulong!,0)
registryset("hkey_current_user oftware/odbc/odbc.ini/"+odbcname,"uid",regstring!,"")
registryset("hkey_current_user oftware/odbc/odbc.ini/"+odbcname+"/engines/jet","implicitcommitsync",regstring!,"")
registryset("hkey_current_user oftware/odbc/odbc.ini/"+odbcname+"/engines/jet","maxbuffersize",regulong!,2048)
registryset("hkey_current_user oftware/odbc/odbc.ini/"+odbcname+"/engines/jet","pagetimeout",regulong!,5)
registryset("hkey_current_user oftware/odbc/odbc.ini/"+odbcname+"/engines/jet","usercommitsync",regstring!,'yes')
else
registryset("hkey_current_user oftware/odbc/odbc.ini/"+odbcname,"dbq",regstring!,filename)
end if
registryset("hkey_current_user oftware/odbc/odbc.ini/odbc data sources",odbcname,regstring!,"microsoft access driver (*.mdb)")
当然,如果数据库有用户名和密码就需要你再写俩键值了。类推的。asa库的注册也是一样的。网上也有很多。不再祥叙。