Click here to Skip to main content
11,480,626 members (64,722 online)
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 22: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 294
1 OriginalGriff 190
2 CPallini 150
3 Richard MacCutchan 150
4 CHill60 130
0 Sergey Alexandrovich Kryukov 8,184
1 OriginalGriff 7,556
2 Sascha Lefèvre 3,114
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2015
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