在建立网络时,Sql异常未处理与网络相关的错误 [英] Sql exception unhandled a network related error whilst establishing a network

查看:77
本文介绍了在建立网络时,Sql异常未处理与网络相关的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在con.open()部分遇到上述错误,错误是"在建立网络时未处理网络相关错误的Sql异常"我该如何解决这个问题?


 public partial class Formlogin:Form 
{
SqlConnection con = new SqlConnection(@"Data Source = MCFOXXY \AIRAPPS; Initial Catalog = dblogin; User ID = sa; Password = ***********");
public Formlogin()
{
InitializeComponent();
}

private void buttonLogin_Click(object sender,EventArgs e)
{
// bool login = false;

// SqlConnection con = new SqlConnection(@"Data Source = MCFOXXY \AIRAPPS; Initial Catalog = dblogin; User ID = sa; Password = *********** ");
con.Open();
// string sql ="从Username ='"的Users中选择* + textBoxNumber.Text +"'和Password ='" + textBoxPassword.Text +"'" ;;
SqlCommand cmd = new SqlCommand(" Select * from Users where Username ='" + textBoxNumber.Text +"'and Password ='" + textBoxPassword.Text +"'");
SqlDataReader dr = cmd.ExecuteReader();
dr = cmd.ExecuteReader();
int count = 0;
while(dr.Read())
{
timer1.Enabled = true;
count + = 1;
}


if(count == 1)
{
MDIParent1 parent = new MDIParent1();
parent.Show();
}
else
{
MessageBox.Show(" Error Login");
}
dr.Close();
con.Close();

}





解决方案

< blockquote>

您好mcfee12345,


这是否连接到远程服务器?根据错误消息,它似乎是一个网络异常。您可以直接通过SSMSE连接到服务器吗?


也许您可以尝试以下方法:


1。检查防火墙白名单。


2。检查用于连接的端口。


3。尝试ping服务器。(如果无法获得结果,请先修复网络)


问候,


Moonlight


I am having the above error on con.open() section the error is "Sql exception unhandled a network related error whilst establishing a network" How can I solve this?

public partial class Formlogin : Form
    {
        SqlConnection con = new SqlConnection(@"Data Source=MCFOXXY\AIRAPPS;Initial Catalog=dblogin;User ID=sa;Password=***********");
        public Formlogin()
        {
            InitializeComponent();
        }

        private void buttonLogin_Click(object sender, EventArgs e)
        {
 // bool login = false;

           //SqlConnection con = new SqlConnection(@"Data Source=MCFOXXY\AIRAPPS;Initial Catalog=dblogin;User ID=sa;Password=***********");
            con.Open();
            //string sql = "Select * from  Users where Username='" + textBoxNumber.Text + "' and Password='" + textBoxPassword.Text + "'  ";
            SqlCommand cmd = new SqlCommand("Select * from  Users where Username='" + textBoxNumber.Text + "' and Password='" + textBoxPassword.Text + "'  ");
            SqlDataReader dr = cmd.ExecuteReader();
            dr = cmd.ExecuteReader();
            int count = 0;
           while (dr.Read())
           {
               timer1.Enabled = true;
               count += 1;
           }

      
           if (count == 1)
           {
               MDIParent1 parent = new MDIParent1();
               parent.Show();
           }
           else
           {
               MessageBox.Show("Error Login");
           }
            dr.Close();
            con.Close();
                
        }

解决方案

Hi mcfee12345,

Does this connect to a remote server? According to the error message, it seems like a network exception. Could your connect to the server by SSMSE directly?

Maybe you could try the following methods:

1. Check the firewall whitelist.

2. Check the port which use to connect.

3. Try to ping the server.(if can't get the result, fix the network first)

Regards,

Moonlight


这篇关于在建立网络时,Sql异常未处理与网络相关的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆