我在打包一个PB做的软件时候遇到了问题。
我的软件用access数据库,使用ODBC数据源。
但是不知道怎么去打包软件,使得安装后能自动根据数据库的位置去创建ODBC,每次我创建的数据库位置都错误,大概是我在ODBC里面选择的ODBC是一个固定路径吧。
有没有人能告诉我。我用的是InstallShield 12。
另外,打包的软件卸载后,在PB里面看不见ODBC了。
------解决方案--------------------
一种方式是用is,这个不熟悉。。
另一种方法是在程序中写注册代码
自动注册数据源,odbc
//获取程序所在目录
String ls_curdir
//ls_curdir=Space(256)
////为字符缓冲区开辟内存空间
//GetCurrentDirectoryA(256,ls_curdir)
ls_curdir = GetCurrentDirectory()
gs_path = ls_curdir
string ls_ob
Registryget("HKEY_LOCAL_MACHINE\Software","ODBC", RegString!, ls_ob)
if ls_ob = '' then
registryset("HKEY_LOCAL_MACHINE\Software\",'odbc',regstring!,'')
end if
registryset("HKEY_LOCAL_MACHINE\Software\odbc",'odbcinst.ini',regstring!,'')
ulong ul_num
Int Answer,Answer1,Answer2,Answer3,Answer4,Answer5,Answer6,Answer7,ansApp
string ls_driver,ls_start,ls_location,apppath,db_path,db_name,ODBCStr,ds_name,ls_dbpath
//设置Adaptive Server Anywhere 8.0的驱动程序路径
ls_Location =ls_curdir
ls_dbpath=ls_curdir+"\gjcx.db"
//判断Adaptive Server Anywhere 8.0的驱动程序是否正确安装
ls_Driver=ls_Location+"\dbodbc8.dll"
ls_Start=ls_Location+"\dbeng8.exe"
//IF Not (FileExists(ls_Driver) AND FileExists(ls_Start)) Then
//MessageBox("错误!","系统中没有安装Adaptive Server Anywhere 7.0"+&
//"的驱动程序,系统将终止运行!",StopSign!)
//Return
//End IF
//设置ODBC\ODBCINST.INI\ODBC DRIVERS
Answer=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST.INI"+&
"\ODBC Drivers","Adaptive Server Anywhere 8.0", RegString!, "Installed")
IF Answer = -1 Then
MessageBox("错误!","应用程序无法设置ODBC\ODBCINST.INI\"+&
"ODBC DRIVERS,系统将终止运行",Information!)
Return
End if
//设置ODBC\ODBCINST.INI\
Answer1=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST."+&
"Adaptive Server Anywhere 8.0", "CPTimeout", RegString!, "not pooled")
Answer2=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST."+&
"INI\Adaptive Server Anywhere 8.0", "Driver", RegString!,ls_Driver)
Answer3=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST."+&
"INI\Adaptive Server Anywhere 8.0", "Setup", RegString!,ls_Driver)
IF Answer1 = -1 OR Answer2 = -1 OR Answer3 = -1 Then
MessageBox("错误!","应用程序无法设置ODBC\ODBCINST.INI,"+&
"系统将终止运行!",Information!)//程序中不折行
Return
End if
db_path = ""+ls_dbpath+""//设置数据库路径及文件名
db_name = "gjcx" //设置数据库名称
ds_name = "gjcx" //设置ODBC数据源名
//设置ODBC DATA SOURCE名称
Answer=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.ini\"+&
"ODBC Data Sources", ds_name, RegString!, "Adaptive Server Anywhere 8.0")
Answer1=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.ini\"+&
ds_name,"driver", Regstring!, ls_Driver)
Answer2=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.ini\"+&
ds_name,"start", Regstring!, ls_Start)
Answer3=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.ini\"+&
ds_name,"autostop", Regstring!, "yes")
Answer4=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.ini\"+&
ds_name,"DataBaseFile", Regstring!, db_path)
Answer5=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.ini\"+&
ds_name,"DataBaseName", Regstring!, db_name)
Answer6=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.ini\"+&
ds_name,"PWD", Regstring!, "sql")