I have a simple login function:
private bool AdminIsValid(string username, string password)
{
bool isValid = false;
using (var db = new AdminEntities())
{
var admin = db.users.FirstOrDefault(u => u.password.Trim() == password);
if (admin != null)
{
if (admin.uname.Trim() == username)
{
isValid = true;
}
}
}
return isValid;
}
That I use like this:
protected void LoginButton_Click(object sender, EventArgs e)
{
if (AdminIsValid(LoginUser.UserName, LoginUser.Password))
{
FormsAuthentication.SetAuthCookie(LoginUser.UserName, false);
Response.Redirect("../");
}
else
{
//"Log in data failed"
}
}
It only works when the login is successful, when it fails I get this error:
Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.