locked
Help with database connection RRS feed

  • Question

  • Hello everyone I'm new on forums and I need help

    I watched tutorial how to make login form and guy from tutorial made this code 
    I tried to change string and everything but it's not working 
    I changed connection string info because of security
    Database is running on my dedicated server

    So if you know where is the problem tell me :)

            private void Login_Click(object sender, EventArgs e)
            {
    
                try
                {
    
    
                    string myConnection = "datasource=IP; port=3306; username=Username; password=password";
                    MySqlConnection myConn = new MySqlConnection(myConnection);
    
                    MySqlCommand SelectCommand = new MySqlCommand("SELECT * FROM timewars.timewars WHERE user='" + this.username_txt.Text + "' AND pass='" + this.password_txt.Text + "' ;", myConn);
    
                    MySqlDataReader myReader;
                    myConn.Open();
                    myReader = SelectCommand.ExecuteReader();
                    int count = 0;
                    while (myReader.Read())
                        count = count + 1;
    
                    if (count == 1)
                        MessageBox.Show("Username and password is correct");
                    else if (count > 1)
                        MessageBox.Show("Duplicate username and password. Access is denied.");
                    else
                        MessageBox.Show("Username and password is incorrect. Please try again.");
    
                    myConn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
    
    
            }

    Friday, April 3, 2015 5:41 PM

Answers

  • If you go to ConnectionStrings.com as Michael suggested, you'd see that you have probably specified the username and password incorrectly in your connection string. According to the link, they should be Uid and Pwd. Try it and see if that solves the problem ... and mark Michael's post as the Answer if it does.

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Marked as answer by Caillen Wednesday, April 15, 2015 9:25 AM
    Saturday, April 4, 2015 4:46 AM
  • This is not a MySQL forum, also there are a lot of third-party forums written by great authors and developers that you should read. For example, http://www.codeproject.com/Articles/43438/Connect-C-to-MySQL.

    Just make sure that you're having all of the assemblies correctly configured and that connection string is properly written; you should also try to look for the connection settings on your server.


    ~!Firewall!~

    • Marked as answer by Caillen Wednesday, April 15, 2015 9:25 AM
    Saturday, April 4, 2015 6:07 AM

All replies

  • Questions related to MySQL should be posted in their forums.  These forums are for questions related to MS products.  For help creating a connection string for a database refer to a site that has connection string examples such as ConnectionStrings.com.

    Michael Taylor
    http://blogs.msmvps.com/p3net

    Friday, April 3, 2015 6:28 PM
  • Hi,

    Please post what error your are occurring?


    PS.Shakeer Hussain

    Friday, April 3, 2015 8:21 PM
  • Hello here is the error (there is no errors in error list)
    I have some issues with my account verifying so I will post image on imgur
    http://i.imgur.com/oIRQD6m.png
    Friday, April 3, 2015 11:35 PM
  • If you go to ConnectionStrings.com as Michael suggested, you'd see that you have probably specified the username and password incorrectly in your connection string. According to the link, they should be Uid and Pwd. Try it and see if that solves the problem ... and mark Michael's post as the Answer if it does.

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Marked as answer by Caillen Wednesday, April 15, 2015 9:25 AM
    Saturday, April 4, 2015 4:46 AM
  • This is not a MySQL forum, also there are a lot of third-party forums written by great authors and developers that you should read. For example, http://www.codeproject.com/Articles/43438/Connect-C-to-MySQL.

    Just make sure that you're having all of the assemblies correctly configured and that connection string is properly written; you should also try to look for the connection settings on your server.


    ~!Firewall!~

    • Marked as answer by Caillen Wednesday, April 15, 2015 9:25 AM
    Saturday, April 4, 2015 6:07 AM