pb生成可EXE檔案,能生成。也可以運行,但無法連接資料庫,我用的是SQL2005,生成exe時,在那些步驟里,我沒見著有設定資料庫的選項,求高手指點,如何才能將資料庫添加進去。能有詳細步驟最好,先行謝過!!
uj5u.com熱心網友回復:
弄個綠色版資料庫試試,幫頂!uj5u.com熱心網友回復:
寫個組態檔,用組態檔關聯資料庫.uj5u.com熱心網友回復:
想程式運行,要確保資料庫能正常訪問。
樓主是想PB生成EXE檔案時把資料庫也打包進去? 這個不可以的。
資料庫需要單獨配置。
uj5u.com熱心網友回復:
我是想把資料庫打包進去,看來現在是不行了,能告訴我在哪配置嗎?uj5u.com熱心網友回復:
可以的,在tools選單下的database profile下添加uj5u.com熱心網友回復:
是不是要把 .mdf和 .ldf檔案一起放在一個目錄里uj5u.com熱心網友回復:
添加dll檔案uj5u.com熱心網友回復:
通過備份的資料庫恢復。備份空庫成.BAK檔案,然后在客戶處運行時直接恢復就可以,并且把組態檔也一起創建。我是這么做的,希望對你有幫助!1、在查詢分析器中,使用 SQL Server restore filelistonly 命令來查看BAK檔案的邏輯檔案名
restore filelistonly from disk='d:/isystem.bak'
查看到邏輯檔案明后,修改CODE中恢復資料庫部分,改成你備份資料庫的邏輯檔案名。
2、視窗

3、資料視窗(exteral)

4、具體CODE
/**************************************************
* 描述:create database
**************************************************/
string ls_execsql , ls_serverinfo , ls_username , ls_pass , ls_repass , ls_dbname , ls_path , ls_null
integer li_ret
long ll_status , ll_current_row
ls_path = gs_currentpath+"\isystem.bak"
//創建資料庫目錄
if directoryexists(gs_currentpath+"\dbname") = false then
createdirectory(gs_currentpath+"\dbname")
end if
dw_1.accepttext()
ll_current_row = dw_1.getrow()
ls_serverinfo = dw_1.getitemstring(ll_current_row , "serverinfo")
if ls_serverinfo = '' or isnull(ls_serverinfo) = true then
messagebox("提示資訊:" , "請填寫服務器名稱或IP!")
dw_1.setfocus()
dw_1.setcolumn(1)
return
end if
ls_username = dw_1.getitemstring(ll_current_row , "dbuser")
ls_pass = trim(dw_1.getitemstring(ll_current_row , "dbpass"))
if ls_pass = '' or isnull(ls_pass) = true then
messagebox("提示資訊:" , "請填寫資料庫登錄密碼!")
dw_1.setfocus()
dw_1.setcolumn(3)
return
end if
ls_repass = trim(dw_1.getitemstring(ll_current_row , "redbpass"))
if ls_repass = '' or isnull(ls_repass) = true then
messagebox('提示資訊:' , "請填寫重復登錄密碼!" )
dw_1.setfocus()
dw_1.setcolumn(4)
return
end if
if ls_pass <> ls_repass then
messagebox('提示資訊:','兩次登錄密碼輸入不一致,請檢查!')
setnull(ls_null)
dw_1.object.dbpass.primary.current = ls_null
dw_1.object.redbpass.primary.current = ls_null
dw_1.setfocus()
dw_1.setcolumn(3)
return
end if
ls_dbname = dw_1.getitemstring(ll_current_row , "dbname")
/*********判斷是否安裝SQL是否已經啟動*********/
oleobject pbobject
pbobject = create oleobject
ll_status = pbobject.connecttonewobject("sqldmo.sqlserver")
if ll_status = 0 then //連接成功
pbobject.name = ls_serverinfo
pbobject.logintimeout = 10
//以sql server方式連接
pbobject.loginsecure = false
li_ret = pbobject.status
if li_ret <> 1 then
destroy(pbobject)
messagebox("提示資訊:","sql server未啟動" , StopSign!)
return
end if
else
destroy(pbobject)
messagebox("提示資訊:","sql server未安裝" , StopSign!)
return
end if
/***************連接資料庫*************/
SQLCA.DBMS = "OLE DB"
SQLCA.LogPass = ls_pass
SQLCA.LogId = ls_username
SQLCA.AutoCommit = true
SQLCA.DBParm = "PROVIDER='SQLOLEDB',"+&
"DATASOURCE='" + ls_serverinfo + "'," +&
"PROVIDERSTRING='Database=master"+"'"
connect using sqlca ;
if sqlca.sqlcode <> 0 then
messagebox("提示資訊:","資料庫連接失敗,請檢查資料庫登錄密碼是否填寫正確!")
return
end if
/***********通過設備檔案恢復資料庫***********/
//創建一個空庫
ls_execsql = "create database "+ ls_dbname
execute immediate :ls_execsql;
if sqlca.SQLCode = 0 then
commit;
else
rollback;
end if
//恢復資料庫
ls_execsql = "restore database "+ls_dbname+" from disk = '"+ls_path+"' with replace , move ~'isystem_Data~' to ~'"+gs_currentpath+"\dbname\isystem_Data.mdf~' , move ~'isystem_Log~' to ~'"+gs_currentpath+"\dbname\isystem_Log.ldf~'"
execute immediate :ls_execsql;
if sqlca.sqlcode = 0 then
commit;
//洗掉資料庫檔案
if fileexists(ls_path) = true then
filedelete(ls_path)
end if
//修改dbms.ini檔案,如果沒有該檔案則直接創建然后寫入
if fileexists(gs_currentpath+"\dbms.ini") = true then
setprofilestring(gs_currentpath+"\dbms.ini" , "database" , "dbname" , ls_dbname)
setprofilestring(gs_currentpath+"\dbms.ini" , "database" , "logid" , ls_username)
setprofilestring(gs_currentpath+"\dbms.ini" , "database" , "logpass" , ls_pass)
setprofilestring(gs_currentpath+"\dbms.ini" , "database" , "serverinfo" , ls_serverinfo)
else
integer li_filenum
li_filenum = fileopen(gs_currentpath+"\dbms.ini" , LineMode! , Write! , LockWrite! , Append!)
fileclose(li_filenum)
setprofilestring(gs_currentpath+"\dbms.ini" , "database" ,"dbname" , ls_dbname)
setprofilestring(gs_currentpath+"\dbms.ini" , "database" ,"logid" , ls_username)
setprofilestring(gs_currentpath+"\dbms.ini" , "database" ,"logpass" , ls_pass)
setprofilestring(gs_currentpath+"\dbms.ini" , "database" ,"serverinfo" , ls_serverinfo)
end if
messagebox("提示資訊:","請關閉該視窗后再次運行isystem程式!")
else
rollback;
messagebox("創建失敗", sqlca.sqlerrtext , Stopsign!)
end if
disconnect using sqlca ;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/44827.html
標籤:數據庫相關
上一篇:高手請進,急急急!!!
下一篇:高手請進,急急急!!!
