Hi,

I have a problem with my login control. I changed the code in order to use my own database (SQL Server 2005) and no matter what i do i get the message "Your login attempt was not successful. Please try again. "!!!

in the web.config file i chose my own connection string leading to my database, so i don't use the default database for the login authorization.

Do i have to change anything else in there?

Check out my code below

Please anyone who can help i really appreciate it!!!!!!!

When I debugged the code I get the exception on the line 55

public partial class _Login : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
    
        }
    
    
       protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
       {
           try
           {
               string uname = Login1.UserName.Trim(); //Get the username from the control
               string password = Login1.Password.Trim(); //get the Password from the control
               bool flag = AuthenticateUser(uname, password);
               if (flag == true)
               {
                   e.Authenticated = true;
                   Login1.DestinationPageUrl = "Admin.aspx";
   
               }
               else
               {
                   e.Authenticated = false;
   
               }
           }
           catch (Exception)
           {
   
               e.Authenticated = false;
           }
       }
   
       private bool AuthenticateUser(string uname, string password)
       {
   
           bool bflag = false;
           string connString = "Data Source = localhost; Initial Catalog = Telemedicine; User Id=sa; Password=sa;";
   
           string strSQL = "select * from Administrator where UserName =’" + uname + "‘ AND Password =’" + password + "‘";
   
           DataSet userDS = new DataSet();
           SqlConnection m_conn;
           SqlDataAdapter m_dataAdapter;
           SqlCommand m_Command;
   
         
           try
           {
               m_conn = new SqlConnection(connString);
               m_conn.Open();
               m_dataAdapter = new SqlDataAdapter(strSQL, m_conn);
               m_dataAdapter.Fill(userDS);
               m_conn.Close();
          }
           catch (Exception ex)
           {
   
               userDS = null;
           }
           if (userDS != null)
           {
               if (userDS.Tables[0].Rows.Count > 0)
   
                   bflag = true;
           }
           return bflag;
       }
      
   }

thank u very much

Nikolas

check t make sure that all your tables column names are the same if you want to use the built in login code.

Else you could just as easy build your own if you have the table already in place.

Thanks ninjaimp.

I found the problem. It was that i had to give permission to access the tables in my db. I didn't know that because i was able to connect to the server but i didn't have access to the db tables.

Hi,
If your problem is solved mark this thread as solved so that fellow posters can concentrate on other posts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.