好的,我的老板使用 VB 制作了这个函数,当我将它转换为 C# 时,它似乎并不想正常工作。我收到“无法将类型 'int' 转换为 'System.Net.NetworkInformation.IPStatus' 错误。我似乎无法纠正它。
static void SetConnectionString(string IpOrHostname)
{
try
{
System.Net.NetworkInformation.Ping MyPing = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply Myreply = MyPing.Send(IpOrHostname);
switch (Myreply.Status)
{
case 11010:
SetConnectionString("10.40.2.x");
break;
//SetText("Connection timeout.")
//SetVisible(True)
case 11003:
ConnectionName = "ATRTS09AltAddress";
strConn = "server=10.40.2.x;User Id=blab;password=xxxx;database=xxxx";
strConn_del = "server=10.40.2.x;User Id=blah;password=xxx;database=xx";
UserConn = "server=10.40.2.x;User Id=glab;password=xxx;database=xxx";
break;
case 0:
ConnectionName = IpOrHostname;
strConn = "server=" + IpOrHostname + ";User Id=blab;password=xxx;database=xx";
strConn_del = "server=" + IpOrHostname + ";User Id=blah;password=xxx;database=xx";
UserConn = "server=" + IpOrHostname + ";User Id=glab;password=xx;database=xxx";
break;
default:
ConnectionName = "ATRTS09";
strConn = "server=atrts09;User Id=foox;password=xx;database=xxx";
strConn_del = "server=atrts09;User Id=gaaa;password=xxx;database=xx";
UserConn = "server=atrts09;User Id=asdfef;password=xxx;database=xxx";
break;
}
}
catch (Exception ex)
{
}
}