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 6647247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:30:53+00:00 2026-05-26T00:30:53+00:00

Hi i have a login which connects to a server string and executes this

  • 0

Hi i have a login which connects to a server string and executes this when the login button is pushed. It returns the invalid error if the user and password is not stored on the database but it throws a “Index was outside on the bounds of array” error if they are on the database. How would i fix this??
Thanks

My connection string is located in my appconfig file, could the problem be in there?

##########FORM WINDOWS AFTER LOGIN BUTTON CLICK

private void btnOK_Click(object sender, EventArgs e)
{
SqlConnection con = Program.GetConnection;
SqlDataReader dr = null;
try
    {
            SqlCommand cmd = new SqlCommand("SELECT * FROM Users WHERE UserName='" +
            txtName.Text + "'AND Password='" + textpassword.Text + "'", con);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                Program.UserLoginName = dr.GetString(3);
                this.Close();
            }
            else

                MessageBox.Show("Invalid Username & Password!");

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

#######PROGRAM.CS FILE

Using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;  

namespace FrontEndV1
{
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Login());
    }
    public static SqlConnection GetConnection
    {
        get
        {
            string ConnectionString = ConfigurationManager.ConnectionStrings["FrontEndV1Connection"].ConnectionString;
            SqlConnection con = new SqlConnection(ConnectionString);
            con.Open();
            return con;
        }
    }
    public static string UserLoginName { get; set; }
}

}

  • 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-05-26T00:30:54+00:00Added an answer on May 26, 2026 at 12:30 am

    I think that mistake lays here: dr.GetString(3); try to change 3 to 2. Numeration begins from 0 in arrays.

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

Sidebar

Related Questions

I have a login window with a Sign In button which is set as
I have a child page LoginContent.aspx which contains a login form. If the user
I have some code in an IAuthorizationFilter which redirects the user to a login
I'm writing an Android application which requires the user to login. I have a
I have Winforms application written in C# which connects to a SQL Server Database.
We have a flex application that connects to a proxy server which handles authentication.
I have an application which connects to SQL Server 2000 (using a generic SQL
I have a login form which appears at the top of all of my
I have a PHP login which sets 2 cookies once someone login. The problem
Hi I want to create a WCF service that have login method, which is

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.