用以下代码判断远程mssql数据源,如果数据源正常,秒出结果;如果数据源不正常,居然需要21秒多,有什么其他办法能够快速判断数据源是否正常?
Dim st As Date = Date.Now
Dim ip As String = Connections("SQL2008数据源").ConnectionString
Dim err As String
If Connections.TryConnect(ip, err) = False Then
_C
End If
MessageBox.Show("耗时: " & (Date.Now - st).TotalSeconds & "秒")
此主题相关图片如下:2.png
[此贴子已经被作者于2024/5/10 16:17:11编辑过]
换种方式判断
Dim st As Date = Date.Now
Dim ip As String = Connections("SQL2008数据源").ConnectionString
Dim conn As System.Data.SqlClient.SqlConnection
Try
conn = New System.Data.SqlClient.SqlConnection(ip .replace("Provider=SQLOLEDB.1;","Connection Timeout=1;"))
conn.Open() '打开链接
Output.Show("OK")
Catch ex As exception
Output.Show(ex.message)
End Try
MessageBox.Show("耗时: " & (Date.Now - st).TotalSeconds & "秒")
[此贴子已经被作者于2024/5/10 17:11:53编辑过]
conn = New System.Data.SqlClient.SqlConnection(
ip .replace("Provider=SQLOLEDB.1;","Connection Timeout=1;"))
这些都是.net的语法,看不懂网上搜搜
又出现
此主题相关图片如下:4.png
去掉加密关键字合适了,谢谢老师!
[此贴子已经被作者于2024/5/10 17:22:56编辑过]