vb6.0 判断连接数据库连没连上怎么写 详细看补充着急啊
Setdb=NewConnectiondb.CursorLocation=adUseClientdb.Open"PROVIDER=MSDASQL;driver={SQLS...
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=MSDASQL;driver={SQL Server};server=122.122.107.56,13000;uid=wa;pwd=gvwsgsg;database=reachDb;"
如果连上 就msgbox“数据库连接成功”
连不上就msgbox“数据库连接失败” 等 求大仙 展开
db.CursorLocation = adUseClient
db.Open "PROVIDER=MSDASQL;driver={SQL Server};server=122.122.107.56,13000;uid=wa;pwd=gvwsgsg;database=reachDb;"
如果连上 就msgbox“数据库连接成功”
连不上就msgbox“数据库连接失败” 等 求大仙 展开
2个回答
展开全部
Function ConnectToDataBase() as Boolean ’定义一个连接数据库的函数,返回值为连接成功与否
On Error GoTo DealErr
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=MSDASQL;driver={SQL Server};server=122.122.107.56,13000;uid=wa;pwd=gvwsgsg;database=reachDb;"
ConnectToDataBase=True
MsgBox "连接数据库成功!"
Exit Function
DealErr:
ConnectToDataBase=False
MsgBox "连接数据库失败!"
End
EndFunction
On Error GoTo DealErr
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=MSDASQL;driver={SQL Server};server=122.122.107.56,13000;uid=wa;pwd=gvwsgsg;database=reachDb;"
ConnectToDataBase=True
MsgBox "连接数据库成功!"
Exit Function
DealErr:
ConnectToDataBase=False
MsgBox "连接数据库失败!"
End
EndFunction
展开全部
如果连不上会出错的,捕捉错误不就得了?
追问
怎么写 请教 我是新手啊
追答
On Error Resume Next
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=MSDASQL;driver={SQL Server};server=122.122.107.56,13000;uid=wa;pwd=gvwsgsg;database=reachDb;"
If Err.Number 0 Then
msgbox“数据库连接失败”
Err.Number=0
Else
msgbox“数据库连接成功”
End if
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询