高手支招——如何用.net程序快速检测与SQL服务器的连接状态?
问题:如何用.net程序快速检测与SQL服务器的连接状态?
我写的检测函数如下:
Public Function Testconn(ByVal UserName As String, ByVal Password As String, ByVal _ ServerName As String) As Boolean
Dim DBConn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection
Dim Strconnection As String
Dim str As String
Try
DBConn.ConnectionString = "User ID=" & UserName & ";Password=" & Password & ";Data Source=" & ServerName & ";Initial Catalog=FireDocument;Auto Translate=True;Persist Security Info=False;Provider=""SQLOLEDB.1"""
DBConn.Open()
Dim pp As New OleDb.OleDbCommand
pp.Connection = DBConn
pp.CommandText = "select top 1 * from sysobjects"
pp.ExecuteNonQuery()
pp.Dispose()
DBConn.Close()
DBConn.Dispose()
Return True
Catch ex As Exception
Return False
End Try
End Function
用这个函数检测,所用时间太长!望高手提供建议和程序代码!! 3Q!