一個(gè)測(cè)試數(shù)據(jù)庫連接的函數(shù)
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
[p]以前一直困擾我的一個(gè)問題,如何判斷數(shù)據(jù)庫連接是否成功(比如sql沒有啟動(dòng),數(shù)據(jù)庫不存在等),實(shí)現(xiàn)友好的錯(cuò)誤處理,但vbscript的錯(cuò)誤處理機(jī)制實(shí)在太差,只有on error resume nex/go to,但往往使用ado的錯(cuò)誤陷阱后,等待你的將是腳本超時(shí),這個(gè)函數(shù)將改變這一狀況(連接超時(shí)長短可以自己根據(jù)實(shí)際情況控制) [/p]
[p][br]'入口參數(shù):連接字符串strconn[br]'返回值:testconnection=true,false[/p] [p]function testconnection(strconn)[br]on error resume next[br]set conn=server.createobject("adodb.connection")[br]'這里設(shè)定連接超時(shí)為10秒[br]conn.connectiontimeout=10[br]conn.open strconn[br]if conn.errors.count = 0 then[br]testconnection = true[br]conn.close[br]else[br]testconnection = false[br]end if[br]set conn=nothing[br]end function[/p] 該文章在 2010/7/7 23:38:13 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |