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();
}