110,538
社区成员
发帖
与我相关
我的任务
分享
using (SqlConnection connection = new SqlConnection("Data Source=192.0.0.0;Initial Catalog=demo;Persist Security Info=True;User ID=demo;Password=demo;Connect Timeout=5"")
{
try
{
connection.Open();//这里问题
}
catch (Exception)
{
}
}
public class sk
{
private int _port = 1433;
private bool _connect;
private IPEndPoint _iPEndPoint;
private TcpClient _client;
private TimerCallback _timerCallBack;
private Timer _timer;
public sk()
{
_iPEndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.30 "), _port);
_timerCallBack = new TimerCallback(CheckConnect);
_timer = new Timer(_timerCallBack, null, 60000, 10000);
}
public bool Connect
{
get { return _connect; }
}
public void CheckConnect(object o)
{
try
{
_client = new TcpClient();
_client.Connect(_iPEndPoint);
_connect = true;
_client.Close();
}
catch
{
_connect = false;
}
}
}