Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8758663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:36:21+00:00 2026-06-13T14:36:21+00:00

I try to autentificate to a database, to create a Login function. Every time

  • 0

I try to autentificate to a database, to create a Login function. Every time I press the button I receive this error: System.InvalidOperationException: The connection is not open. at MySql.Data.MySqlClient.MySqlConnection.Throw(Exception ex) at MySql.Data.MySqlClient.MySqlCommand.Throw(Exception ex) at MySql.Data.MySqlClient.MySqlCommand.Prepare() at start.CheckUserLogin(String username, String password) in c:\Users\RARES\Documents\Visual Studio 2010\WebSites\tem1\start.aspx.cs:line 46

Please tell me how can I read the data and check if the user and pass are the same as the ThextBox texts.

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        String sCon = "SERVER=localhost;DATABASE=sd_tema1;UID=root;";
        MySqlConnection con = new MySqlConnection(sCon);

        if (CheckUserLogin(Label2.Text, Label3.Text))
        {
            Response.Redirect("login.aspx");
        } 

    }
    catch (Exception ex)
    {
        Label1.Text = ex.ToString();
    }
}

public Boolean CheckUserLogin(string username, string password)
{
    try
    {
        String sCon = "SERVER=localhost;DATABASE=sd_tema1;UID=root;";
        MySqlConnection con = new MySqlConnection(sCon);

        String query = "Select * from users where username= ?userName and password= ?passWord";
        MySqlCommand cmd = new MySqlCommand(query,con);
        cmd.Parameters.Add("?userName", TextBox1.Text);
        cmd.Parameters.Add("?passWord", TextBox2.Text);
        cmd.Prepare();
        MySqlDataReader print = cmd.ExecuteReader();
        bool read = print.Read();
        if(username.Equals(print.GetString("1")) && password.Equals(print.GetString("2"))) return true;
    }
    catch (Exception ex)
    {
        Label1.Text = ex.ToString();
    }
    return false;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:36:22+00:00Added an answer on June 13, 2026 at 2:36 pm

    You didn’t open the connection before calling ExecuteReader method. Call con.Open. Your issue will be resolved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Try to execute this 2 code blocks in error console: First one. Outputs NodeList.
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
Try this in chrome versus firefox/IE: var cancelPressed = false; function redirect() { //window.location
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
try { if (myBoolean) { while (true) ; } else { System.exit(1); } }
try: html = urlopen('http://glbse.com/api/asset/' + asset.name) except: print 'error while updating the price of
try: recursive_function() except RuntimeError e: # is this a max. recursion depth exceeded exception?
try { if (check) { while (true) ; } else { System.exit(1); } }
Try running this in iOS6 (haven't tested pre iOS6): NSDateFormatter *julianDayDateFormatter = nil; julianDayDateFormatter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.