求助高人,?数据库为什么有时连接失败?网络没问题?

[复制链接]
查看11 | 回复1 | 2021-1-27 06:48:25 | 显示全部楼层 |阅读模式
PublicFunctionOpenConnect()AsSqlConnection
Try
DimconnectionStringAsString=_
"PersistSecurityInfo=False;UserID=admin;Password=admin123;InitialCatalog=BPP2;DataSource="&DataServer&";FailoverPartner=tb-mirror;"

DimConnectAsNewSqlConnection(connectionString)
IfConnect.State=ConnectionState.ClosedThen
Connect.Open()
EndIf
ReturnConnect
CatchexAsException
MsgBox("连接数据库失败!",MsgBoxStyle.Critical,"NetworkWrong")
EndTry
ReturnNothing
EndFunction
这是我连接数据库代码?
我每次访问数据库都进入该过程判断连接是否打开/.......?
程序运行每天都要报几次"连接数据库失败"的错误..
程序有多台电脑同时使用,每次报错的时候不是全部电脑报错,因此我觉得不太可能是网络的问题?

访问数据库的方法一般都是用
mydr=NewSqlDataAdapter(strSql,OpenConnect)

DimCmdAsNewSqlCommand
Cmd.Connection=OpenConnect()
Cmd.CommandText="Select*fromsysLanguage"
DimReaderAsSqlClient.SqlDataReader=Cmd.ExecuteReader

请问是什么原因引起"数据库连接失败!"



分 -->
回复

使用道具 举报

千问 | 2021-1-27 06:48:25 | 显示全部楼层
谁告诉你说ConnectionState只有Open和Close两种状态啊
IfConnect.State=ConnectionState.ClosedThen
Connect.Open()
EndIf
改成
IfConnect.StateConnectionState.OpenThen
Connect.Open()
EndIf
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行