我發現很多的同志不知道如何脫離自己的開發主機,在別人的計算機上獨立運行。其實很簡單,關鍵在于怎樣在注冊表中自動注冊你的asa數據源。
現在我把以前我發的帖子再發一次。希望對初學者有幫助!
大家用pb編好的程序,用安裝軟件(例如:installshile,installwais,creatinstall等)安裝打包后,在用戶機上一使用就出現數據庫沒有連接等問題,原因就是我們沒有在windows的注冊表中注冊我們的數據源。怎樣注冊呢?現在我來說一下:
首先我們用安裝軟件把我們的主運行文件要注冊到注冊表中的hkey_local_machine oftware/microsoft/windows/currentversion/app paths里,在這里我的主應用程序是idmis.exe,數據庫文件是wts.db。數據庫是pb8自帶的asa 7數據庫,原來的asa 5數據庫的文件和asa 7不一樣,要注意。
"注冊表注冊數據源"(w_regdatasorce)的open事件:
string ls_keyname
string ls_valuename
string ls_value
int li_a,li_a1,li_a2,li_a3,li_a4,li_a5,li_a6,li_a7
string ls_dbdriver,ls_dbstart,ls_dblocation,ls_wtslocation,ls_dbname,ls_db_dbeng7
//獲取本軟件的目錄,并保存在ls_location里
registryget("hkey_local_machine oftware/microsoft/windows/currentversion/app paths/idmis.exe","path",ls_wtslocation)
ls_dbdriver=ls_wtslocation+"/dbodbc7.dll"
ls_db_dbeng7=ls_wtslocation+"/dbeng7.exe"
ls_dbname=ls_wtslocation+"/wts.db"
ls_dbstart=ls_wtslocation+"/dbeng7.exe -d -c8m"
if not (fileexists(ls_dbdriver) and fileexists(ls_db_dbeng7)) then
messagebox("錯誤!","沒有安裝sybase asa 7數據庫,或者沒有數據庫主控文件!",stopsign!)
return
end if
//設置odbc/odbcinst.ini/odbc drivers
li_a=registryset("hkey_local_machine oftware/odbc/odbcinst.ini/odbc drivers", &
+"sybase asa 7(函授學生信息查詢數據庫文件)", &
+regstring!,"installed")
if li_a=-1 then
messagebox("錯誤!","應用程序無法在注冊表中設置odbc drivers,請與作者聯系!",stopsign!)
return
end if
//設置....odbc/odbcinst.ini
li_a1=registryset("hkey_local_machine oftware/odbc/odbcinst.ini ybase asa 7(函授學生信息查詢數據庫文件)", &
+"cptimeout",regstring!,"not pooled")
li_a2=registryset("hkey_local_machine oftware/odbc/odbcinst.ini ybase asa 7(函授學生信息查詢數據庫文件)", &
+"driver",regstring!,ls_dbdriver)
li_a3=registryset("hkey_local_machine oftware/odbc/odbcinst.ini ybase asa 7(函授學生信息查詢數據庫文件)", &
+"setup",regstring!,ls_dbdriver)
if li_a1=-1 or li_a2=-1 or li_a3=-1 then
messagebox("錯誤!","應用程序無法設置注冊表中odbcinst.ini,請與作者聯系!",stopsign!)
return
end if
//設置odbc data source(odbc數據源),wts為數據源名稱
li_a=registryset("hkey_local_machine oftware/odbc/odbc.ini/odbc data sources", &
+"wts",regstring!,"sybase asa 7(函授學生信息查詢數據庫文件)")
if li_a=-1 then
messagebox("錯誤!","應用程序無法設置注冊表odbc data source,請與作者聯系!",stopsign!)
return
end if
li_a=registryset('hkey_local_machine oftware/odbc/odbc.ini/wts','driver',regstring!,ls_dbdriver)
li_a1=registryset('hkey_local_machine oftware/odbc/odbc.ini/wts','start',regstring!,ls_dbstart)
li_a2=registryset('hkey_local_machine oftware/odbc/odbc.ini/wts','autostop',regstring!,'yes')
li_a3=registryset('hkey_local_machine oftware/odbc/odbc.ini/wts','databasefile',regstring!,ls_dbname)
li_a4=registryset('hkey_local_machine oftware/odbc/odbc.ini/wts','databasename',regstring!,'wts')
li_a5=registryset('hkey_local_machine oftware/odbc/odbc.ini/wts','enginename',regstring!,'函授學生信息查詢系統')
li_a6=registryset('hkey_local_machine oftware/odbc/odbc.ini/wts','pwd',regstring!,'sql')
li_a7=registryset('hkey_local_machine oftware/odbc/odbc.ini/wts','uid',regstring!,'dba')
if li_a=-1 or li_a2=-1 or li_a3=-1 or li_a4=-1 or li_a1=-1 or li_a5=-1 or li_a6=-1 or li_a7=-1 then
messagebox('錯誤','應用程序無法設置odbc.ini,系統將終止運行!',stopsign!)
return
end if
如果你要設置用戶級的odbc連接請對下面的鍵值進行設置:
置'hkey_current_user oftware/odbc/odbc.ini'
內容都是一樣的。看看自己windows中的odbc設置,有沒有變化??
好人作到底!我在付上脫離環境后所需的.dll文件:
pbvm8.dll //pb虛擬機
pbdwe8.dll //dw引擎
pbodb8.dll //odbc配置文件
pbodb8.inf //同上
dbodbc7.dll //數據庫連接文件
dbeng7.exe //數據庫啟動文件。如果你是網絡運行,那么就是dbserv7.exe
libjcc.dll //我不知道 :-p
如果你有rich text對象控件,則: pbrtc.dll
如果你有ole對象,則:pbole7.dll
好了沒有,你成功了嗎??