Home > Blockchain >  c# trying to use remote sql server for my login but not work
c# trying to use remote sql server for my login but not work

Time:04-14

I'm trying to make login panel before I worked with local host sql server its worked well but now I want to work with remote sql server but when I try to run application I got some error codes and error below

using System.Data.SqlClient;
SqlConnection connect = new SqlConnection(@"Data Source=MyServerIpAddress;Initial Catalog=TelegramAutoPostBot;User ID=admin;Password=Password123@");
private void Login_Load(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = connect;
        cmd.CommandText = ("Select * from TOPB_Login where TOPB_EmailAddress=@p1,TOPB_LicenseKey=@p2");
        cmd.Parameters.AddWithValue("@p1", textBox1.Text);
        cmd.Parameters.AddWithValue("@p2", textBox2.Text);
        connect.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        if (reader.Read())
        {
            MessageBox.Show("Login Success Redirecting to Control Panel", "Auto Post", MessageBoxButtons.OK, MessageBoxIcon.Information);
            MainMenu menu = new MainMenu();
            menu.Show();
            this.Hide();
            connect.Close();
        }
        else
        {
            MessageBox.Show("Wrong Email Address or Serial Key ", "Auto Post", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

Error Image : https://i.stack.imgur.com/Y2Nrp.png

CodePudding user response:

Your comma seperating your where commands, you want the key word AND

using System.Data.SqlClient;
SqlConnection connect = new SqlConnection(@"Data Source=MyServerIpAddress;Initial Catalog=TelegramAutoPostBot;User ID=admin;Password=Password123@");
private void Login_Load(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = connect;
        cmd.CommandText = ("Select * from TOPB_Login where TOPB_EmailAddress=@p1 AND TOPB_LicenseKey=@p2");
        cmd.Parameters.AddWithValue("@p1", textBox1.Text);
        cmd.Parameters.AddWithValue("@p2", textBox2.Text);
        connect.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        if (reader.Read())
        {
            MessageBox.Show("Login Success Redirecting to Control Panel", "Auto Post", MessageBoxButtons.OK, MessageBoxIcon.Information);
            MainMenu menu = new MainMenu();
            menu.Show();
            this.Hide();
            connect.Close();
        }
        else
        {
            MessageBox.Show("Wrong Email Address or Serial Key ", "Auto Post", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

CodePudding user response:

You can try code below, you missing keyword AND in where clause

cmd.CommandText = ("Select * from TOPB_Login where TOPB_EmailAddress=@p1 AND TOPB_LicenseKey=@p2");
  • Related