Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
I am trying to built an asp.net application in which there is a Login Page.
 
In this login page i am using an ASP.Net Login Control, i am using database as an mysql.
 
I am getting an error while login as :
 
Keyword not supported.
Parameter name: serverlocalhost;user id
 
NOTE : the error section is heighlighted in BOLD
 
My C# ASP.Net Code looks like this :
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
 
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
ViewState["LoginError"] = 0;
}
 
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
if(YourValidationFunction(Login1.UserName, Login1.Password))
{
Login1.Visible = true;
Label1.Text = " Successfully Logged in ";
}
else{
e.Authenticated = false;
}
}
 
protected void Login1_LoginError(object sender, AuthenticateEventArgs e)
{
if (ViewState["LoginErrors"] == null)
ViewState["LoginErrors"] = 0;
 
int ErrorCount = (int)ViewState["LoginErrors"] + 1;
ViewState["LoginErrors"] = ErrorCount;
 
if ((ErrorCount > 3) && (Login1.PasswordRecoveryUrl != string.Empty))
Response.Redirect(Login1.PasswordRecoveryUrl);
 
}
 
private bool YourValidationFunction(string UserName, string Password)
{
bool boolReturnValue = false;
string con = string.Format("server{0};user id={1}; password={2};" + "database=mydb;pooling=false", "localhost", "root", "root");
MySql.Data.MySqlClient.MySqlConnection mycon = new MySqlConnection(con);

if (mycon.State != System.Data.ConnectionState.Open)
{
try
{
mycon.Open();
}
catch (MySqlException ex)
{
throw (ex);
}
}
string SQLQuery = "SELECT UserName,Password from Login ";
 
MySqlCommand command = new MySqlCommand(SQLQuery, mycon);
MySqlDataReader Dr;
mycon.Open();
Dr = command.ExecuteReader();
while (Dr.Read())
{
if ((UserName == Dr["UserName"].ToString()) & (Password == Dr["Password"].ToString()))
{
boolReturnValue = true;
}
Dr.Close();
return boolReturnValue;
}
return boolReturnValue;
}
}
Posted 17-Dec-12 21:24pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Equal to (=) is missing in your connection string. Your connection string should be like this
 
string con = string.Format("server={0};user id={1}; password={2};" + "database=mydb;pooling=false", "localhost", "root", "root"); 
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 354
1 Richard MacCutchan 320
2 OriginalGriff 255
3 Vinay Mistry 168
4 Jared Sanow 145
0 Sergey Alexandrovich Kryukov 5,939
1 OriginalGriff 4,885
2 CPallini 2,473
3 Abhinav S 1,507
4 Richard MacCutchan 1,437


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100