111,098
社区成员




public static bool TestConnection(string host, int port, int millisecondsTimeout)
{
var client = new TcpClient();
try
{
var ar = client.BeginConnect(host, port, null, null);
ar.AsyncWaitHandle.WaitOne(millisecondsTimeout);
return client.Connected;
}
catch
{
return false;
}
finally
{
client.Close();
}
}
public static bool TestConnection(string ConnectionString)
{
bool result = true;
try
{
SqlConnection m_myConnection = new SqlConnection(ConnectionString);
m_myConnection.Open();
m_myConnection.Close();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
result = false;
}
return result;
}