title: C# UWP Login form checking credentials in MySQL remote database
body: <p>I got stuck after couple of hours of research. I'm trying to make a basic Universal Windows App with login form - after clicking a button, credentials in textboxes are checked with remote MySQL database. If valid, app shoud navigate to another specified page. If not, error message is displayed. </p>
  
  <p>I can't find error in my code below. After clicking the button Windows' blue circle spins and after couple of seconds returns to VS2017. No errors and warnings. State.ToString() returns 'Open' so I do have a connection with DB. What I'm doing wrong?</p>
  
  <pre><code>    public sealed partial class MainPage : Page
  {
      const string connString = "server=my_server;pwd=pass;uid=user_id;database=mydb;persistsecurityinfo=True";
      MySqlConnection conn = new MySqlConnection(connString);
  
      public MainPage()
      {
          this.InitializeComponent();
      }
  
      private void DbConnection()
      {
          try
          {
              conn.Open();
          }
          catch (MySqlException e)
          {
              throw;
          }
      }
  
      private bool DataValidation(string user, string pass)
      {
          DbConnection();
          MySqlCommand cmd = new MySqlCommand("SELECT Username, Password FROM Users WHERE Username=@user AND Password=@pass;");
  
          cmd.Parameters.AddWithValue("@user", user);
          cmd.Parameters.AddWithValue("@pass", pass);
          cmd.Connection = conn;
  
          MySqlDataReader login = cmd.ExecuteReader();
          if (login.Read())
          {
              conn.Close();
              return true;
          }
          else
          {
              conn.Close();
              return false;
          }
      }
  
      private void LoginBtn_Click(object sender, RoutedEventArgs e)
      {
          string user = UserTextBox.Text;
          string pass = PassTextBox.Text;
  
          if (user == "" || pass == "")
          {
              StatusTextBlock.Text = ("No emty fields allowed. Try again...");
              return;
          }
  
          bool loginSuccessful = DataValidation(user, pass);
  
          if (loginSuccessful)
          {
              this.Frame.Navigate(typeof(Page2), null);
          }
          else
          {
              StatusTextBlock.Text = "Invalid e-mail or password. Try again...";
          }
      }
  }
  </code></pre>