The code was executing fine but now an exception is generated: "exc = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}" -
protected void bsin_Click(object sender, EventArgs e)
-
{
-
con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
-
com = new SqlCommand("Select *From register Where loginname=@loginname And password=@password", con);
-
com.Parameters.Add("@loginname", SqlDbType.NVarChar).Value = txtun.Text;
-
com.Parameters.Add("@password", SqlDbType.NVarChar).Value = txtpass.Text;
-
try
-
{
-
if (con.State == ConnectionState.Closed)
-
con.Open();
-
dr = com.ExecuteReader();
-
if (dr.Read())
-
{
-
Session["username"] = txtun.Text;
-
Session["password"]=txtpass.Text;
-
lplwronguserid.Visible = false;
-
Response.Redirect("home.aspx");
-
-
-
}
-
else
-
{
-
lplwronguserid.Text = "Wrong Password OR UserID*";
-
//Response.Write("Wrong Password OR UserID");
-
-
-
}
-
}
-
catch (Exception exc)
-
{
-
}
-
finally
-
{
-
con.Close();
-
}
-
-
-
-
-
-
}
-
16 12612
You have: - Select *From register Where loginname=@loginname And password=@password
But you need a space in between the * and the From...like this: - Select * From register Where loginname=@loginname And password=@password
-Frinny
I have changed that as well but still it is showing the same problem
This looks like a java/C/C+/C# code. In SQL Server, a "@" sign means it's a variable. In this case those variables are undeclared. That could be the reason for your error. As to some programming languages, it may be unassigned, but it can not be undeclared.
Good Luck!!!
~~ CK
It's C#, the variables are declared though...they are being assigned values from TextBoxes on the page here: -
com.Parameters.Add("@loginname", SqlDbType.NVarChar).Value = txtun.Text;
-
com.Parameters.Add("@password", SqlDbType.NVarChar).Value = txtpass.Text;
It is often helpful if you tell people which statement is throwing the exception. From looking on google it appears that this isn't a SQL Server problem at all.
I believe the exception is being thrown at Response.Redirect statement at line 17. Here is an MSDN article on the exception and how you can fix it. http://support.microsoft.com/kb/312629/EN-US/
I would never have guessed that it was a Response.Redirect issue (I myself have never experienced this particular error...usually the Response.Redirect("url") method throws "thread abortion error" instead of the error described)
But...change line 17 in the above code from this: - Response.Redirect("home.aspx");
To this: - Response.Redirect("home.aspx",true);
Providing "true" as the second parameter to the Response.Redirect() method will prevent the rest of the page from being executed. This will avoid "thread abortion" errors.
Be Sure to Close your connection Before you Response.Redirect away from the page!
It might be best to use a boolean to flag whether or not to Response.Redirect the user...like this: -
protected void bsin_Click(object sender, EventArgs e)
-
{ boolean redirectUser = false;
-
con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
-
com = new SqlCommand("Select *From register Where loginname=@loginname And password=@password", con);
-
com.Parameters.Add("@loginname", SqlDbType.NVarChar).Value = txtun.Text;
-
com.Parameters.Add("@password", SqlDbType.NVarChar).Value = txtpass.Text;
-
try
-
{
-
if (con.State == ConnectionState.Closed)
-
con.Open();
-
dr = com.ExecuteReader();
-
if (dr.Read())
-
{
-
Session["username"] = txtun.Text;
-
Session["password"] = txtpass.Text;
-
lplwronguserid.Visible = false;
-
redirectUser = true;
-
}
-
else
-
{
-
lplwronguserid.Text = "Wrong Password OR UserID*";
-
-
}
-
}
-
catch (Exception exc)
-
{
-
}
-
finally
-
{
-
con.Close();
-
}
-
if(redirectUser)
-
{
-
Response.Redirect("home.aspx",true);
-
}
-
}
-Frinny
thanks frinny ,
Now it is redirecting but exception is still there
Jagdeep,
What line of code is the exception being thrown at?
Where is it being thrown?
You have a Try-Catch block that catches all Exceptions and does nothing with them....
-Frinny
line no 34
n thanks for considering my request
Is this a ThreadAbortException? How are you seeing the exception?
ASP.NET will abort threads to handle control flow. If you do a Response.Redirect it calls Response.End which does the Thread.Abort(). This should not be an issue.
no sir the exception is same as written above by me
jagdeep gupta,
Could you please post your updated code so that we can see what is going on?
-Frinny
-
-
using System;
-
using System.Data;
-
using System.Configuration;
-
using System.Collections;
-
using System.Web;
-
using System.Web.Security;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.WebControls.WebParts;
-
using System.Web.UI.HtmlControls;
-
using System.Data.SqlClient;
-
-
public partial class loginpage : System.Web.UI.Page
-
{
-
SqlConnection con;
-
SqlCommand com;
-
SqlDataReader dr;
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
//Response.Write("Welcome" + " " + Session["username"]+ " " + Session["lastname"]);
-
-
}
-
-
protected void lbnew_Click(object sender, EventArgs e)
-
{
-
Response.Redirect("registration.aspx");
-
-
}
-
protected void bsin_Click(object sender, EventArgs e)
-
{
-
con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
-
com = new SqlCommand("Select * From register Where loginname=@loginname And password=@password", con);
-
com.Parameters.Add("@loginname", SqlDbType.NVarChar).Value = txtun.Text;
-
com.Parameters.Add("@password", SqlDbType.NVarChar).Value = txtpass.Text;
-
try
-
{
-
if (con.State == ConnectionState.Closed)
-
con.Open();
-
dr = com.ExecuteReader();
-
if (dr.Read())
-
{
-
Session["username"] = txtun.Text;
-
Session["password"]=txtpass.Text;
-
lplwronguserid.Visible = false;
-
con.Close();
-
Response.Redirect("home.aspx",true);
-
-
-
}
-
else
-
{
-
lplwronguserid.Text = "Wrong Password OR UserID*";
-
//Response.Write("Wrong Password OR UserID");
-
-
-
}
-
}
-
catch (Exception exc)
-
{
-
}
-
finally
-
{
-
con.Close();
-
}
-
-
-
-
}
-
Jagdeep Gupta,
I mentioned before that you should do your redirect after you close your connection.
I also mentioned that you should use Response.Redirect("url", true) to redirect the user so that you avoid problems with Thread Abortion exceptions.
Like This: -
using System;
-
using System.Data;
-
using System.Configuration;
-
using System.Collections;
-
using System.Web;
-
using System.Web.Security;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.WebControls.WebParts;
-
using System.Web.UI.HtmlControls;
-
using System.Data.SqlClient;
-
-
public partial class loginpage : System.Web.UI.Page
-
{
-
SqlConnection con;
-
SqlCommand com;
-
SqlDataReader dr;
-
protected void Page_Load(object sender, EventArgs e)
-
{ }
-
-
protected void lbnew_Click(object sender, EventArgs e)
-
{
-
Response.Redirect("registration.aspx", true);
-
}
-
protected void bsin_Click(object sender, EventArgs e)
-
{
-
con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
-
com = new SqlCommand("Select * From register Where loginname=@loginname And password=@password", con);
-
com.Parameters.Add("@loginname", SqlDbType.NVarChar).Value = txtun.Text;
-
com.Parameters.Add("@password", SqlDbType.NVarChar).Value = txtpass.Text;
-
try
-
{
-
if (con.State == ConnectionState.Closed)
-
con.Open();
-
dr = com.ExecuteReader();
-
if (dr.Read())
-
{
-
Session["username"] = txtun.Text;
-
Session["password"]=txtpass.Text;
-
lplwronguserid.Visible = false;
-
con.Close();
-
//I removed the redirect from here
-
}
-
else
-
{
-
lplwronguserid.Text = "Wrong Password OR UserID*";
-
}
-
}
-
catch (Exception exc)
-
{
-
}
-
finally
-
{
-
con.Close();
-
}
-
-
//I put it HERE...after closing the connection
-
if( Session["username"] != null)
-
{
-
Response.Redirect("home.aspx",true);
-
}
-
}
-
}
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Zeng |
last post by:
Hello,
I just wonder if there is a way to programmatically evaluate expression
strings such as
( ( 3 + 5 ) / 2 ) > 4 --> this should return 0 or false
( ( 3 + 6 ) / 3 ) > ( ( 5 + 3 ) / 4 ) ...
|
by: mark |
last post by:
In the sample code for Programming Microsoft Visual Basic.NET by Francesco
Balena (Microsoft Press) there is a program (ExprEvaluator) that evaluates
expressions. It has a bug in that when the...
|
by: bazzer |
last post by:
hey,
i am using visual basic.net 2003 and have an ASP.NET webform
application thats accessing a microsoft access 2003 database. i kept
getting the following error when i tried to run it:
ERROR ...
|
by: bazzer |
last post by:
hey,
im trying to access a microsoft access database from an ASP.NET web
application in visual basic 2003.NET. i get the following error when i
try running it:
Server Error in...
|
by: steevehetu18 |
last post by:
Hi,
I'm doing a algorithm to calcule Earliest Start et Latest Start for a
Graph with Nodes and Arcs. (like a PERT diagram) . Unfortunatly, i
receive a wierd exception message for a specific...
|
by: Rick Little |
last post by:
While stepping through code, I've started getting this message when tying to
see the value of most variables.
Cannot evaluate expression because a thread is stopped at a point where
garbage...
|
by: Ajit Goel |
last post by:
Hi;
My project file property is set to use "Visual Studio Development
Server". I am able to debug and see the corresponding values when I
mouseover but as soon as I change to the project file...
|
by: Glenn |
last post by:
OK, I've looked up this message but am not finding how to get rid of
it: "Cannot evaluate expression because a thread is stopped at a point
where garbage collection is impossible, possibly because...
|
by: tbh |
last post by:
in an error path in an aspx script under DotNet 2, IIS6, Win2003 Server I
get the following error (which I don't understand) on Respone.End():
{Unable to evaluate expression because the code is...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |