首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > PB >

InstallSheild 打包软件ODBC的有关问题

2012-02-13 
InstallSheild 打包软件ODBC的问题我在打包一个PB做的软件时候遇到了问题。我的软件用access数据库,使用ODB

InstallSheild 打包软件ODBC的问题
我在打包一个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")


Answer7=RegistrySet("HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.ini\"+&
ds_name,"UID", Regstring!, "dba")
IF Answer = -1 Then
MessageBox("错误!","应用程序无法设置ODBC DATA SOURCE名称,"+&
"系统将终止运行!",Information!) //程序中不折行
Return
End if
//====================================================================
// 设置ODBC.ini细节
//====================================================================
answer1 = RegistrySet("HKEY_current_user\software\odbc\odbc.ini\"+&
ds_name,"driver", regstring!, ls_driver)
answer2 = RegistrySet("HKEY_current_user\software\odbc\odbc.ini\"+&
ds_name,"start", regstring!, ls_start)
answer3 = RegistrySet("HKEY_current_user\software\odbc\odbc.ini\"+&
ds_name,"autostop", regstring!, "yes")
answer4 = RegistrySet("HKEY_current_user\software\odbc\odbc.ini\"+ds_name,&
"DataBaseFile", regstring!, db_path)
answer5 = RegistrySet("HKEY_current_user\software\odbc\odbc.ini\"+ds_name,&
"DataBaseName", regstring!, db_name)
answer6 = RegistrySet("HKEY_current_user\software\odbc\odbc.ini\"+ds_name,&
"pWD", regstring!, "sql")
answer7 = RegistrySet("HKEY_current_user\software\odbc\odbc.ini\"+ds_name,&
"UID", regstring!, "dba")
If answer1 = -1 Or answer2 = -1 Or answer3 = -1 Or &
answer4 = -1 Or answer5 = -1 Or answer6 = -1 Or answer7 = -1 Then
MessageBox("错误!","应用程序无法设置ODBC.INI细节,"+&
"系统将终止运行!",information!)
Return
End If
odbcstr = 'dsn=' + ds_name +';databasename=' + db_name + ';databasefile=' + db_path
sqlca.DBMS = "ODBC"
sqlca.Database = db_name
sqlca.DBParm = "c"
CONNECT Using sqlca;
If sqlca.SQLCode = -1 Then
MessageBox("数据库连接失败", "不能连接到数据库上,请检查。"+&
"~r~n出错的详细原因为:"+sqlca.SQLErrText)
Halt
End If

热点排行