Home > Net >  The first time in the System. Web. HttpException occasional "System. Web. DLL" type of exc
The first time in the System. Web. HttpException occasional "System. Web. DLL" type of exc

Time:09-19

Novice first, debugging for many times, emerged a large number of exceptions, the database interpolation has been not achieve them, crying , the problems appeared in the cmd1. ExecuteNonQuery (); Here
Protected void Button1_Click (object sender, EventArgs e)
{
String vusername=username. Text. The Trim ();
String vpassword=password. Text. The Trim ();
String vvname=vname. Text. The Trim ();
String vsex=sex. SelectedItem. Text. The ToString ();
String vid=sid. Text. The Trim ();
String vphone=phonenumber. Text. The Trim ();
String vmail=mail. Text. The Trim ();
String vtype="Visitor";

String sqltext="select * from AllUser where username='" + vusername +"' ";
String sqltext1="insert into AllUser (username, password, type) values ('" + vusername + "', '" + vpassword +"', '" + vtype + ") ";

String sqltext2="insert into the Visitor (username, vname, sex, id, phonenumber, E-mail) values ('" + vusername + "', '" + vvname +"', '" + vsex + "', '" + vid + "', '" + vphone + "', '" + vmail + ") ";

Try
{
String connStr=@ "Data Source=. \ SQLEXPRESS; AttachDbFilename=D: \ Travel Self -help System \ App_Data \ Travel MDF. Integrated Security=True; The User Instance=True ";
SqlConnection conn=new SqlConnection (connStr);
conn.Open();
SqlCommand CMD=new SqlCommand (sqltext, conn);
SqlDataReader Dr=CMD. ExecuteReader ();

If (Dr. Read ())
{
Response. Write (" & lt; script> Alert (' user name already exists! '); </script>" );
Response. Redirect (" VisitorRegister. Aspx ");
}
The else
{

SqlCommand cmd1=new SqlCommand (sqltext1, conn);
Cmd1. ExecuteNonQuery ();
SqlCommand cmd2=new SqlCommand (sqltext2, conn);
Cmd2. ExecuteNonQuery ();
Response. Write (" & lt; script> Alert (' registered success! '); </script>" );
Response. Redirect (" Login. Aspx ");

/* if (cmd1 ExecuteNonQuery () & gt; 0 & amp; & Cmd2. ExecuteNonQuery () & gt; 0)
{
Response. Write (" & lt; script> Alert (' registered success! '); </script>" );
Response. Redirect (" Login. Aspx ");
} */
}
conn.Close();

}
Catch
{

Response. Write (" there is an error, please check your fill in ");
The Response. The End ();
}


}

Abnormal mainly include:
The first time in the System. Web. HttpException occasional "System. Web. DLL" type of exception other information: unable to validate data
The first time in the System. Web. HttpException occasional "System. Web. DLL" type of exception
The first time in the System. UnauthorizedAccessException occasional "mscorlib. DLL" type of exception
The first time in the System. InvalidOperationException occasional "System. Web. DLL" type of exception
The first time in the System. UnauthorizedAccessException occasional "mscorlib. DLL" type of exception
The first time in the System. InvalidOperationException occasional "System. Web. DLL" type of exception
The first time in the System. InvalidOperationException occasional "System. Web. DLL" type of exception
The first time in the System. UnauthorizedAccessException occasional "mscorlib. DLL" type of exception
The first time in the System. InvalidOperationException occasional "System. Web. DLL" type of exception
The first time in the System. InvalidOperationException occasional "System. Web. DLL" type of exception
The first time in the System. UnauthorizedAccessException occasional "mscorlib. DLL" type of exception
The first time in the System. InvalidOperationException occasional "System. Web. DLL" type of exception

CodePudding user response:

SqlDataReader after use is need to be closed, cmd1 execution ExecuteNonQuery with Dr. Close ();

CodePudding user response:

With Dr Close not to close it doesn't matter..

This code if you didn't guess wrong words should be a pop-up "there is an error, please check your fill in" isn't it?

But you use let you lose the chance of a debug the try.

At the very least, you have to throw exceptions to come out to know the specific error.. You this code to run unless the breakpoint, don't know the specific error.

Not come up should be a database connection fails or the password is not correct.

The way you local database is attached? Can directly connected?

CodePudding user response:

refer to the second floor by_ love reply:
with Dr Close not to close it doesn't matter..

This code if you didn't guess wrong words should be a pop-up "there is an error, please check your fill in" isn't it?

But you use let you lose the chance of a debug the try.

At the very least, you have to throw exceptions to come out to know the specific error.. You this code to run unless the breakpoint, don't know the specific error.

Not come up should be a database connection fails or the password is not correct.

The way you local database is attached? Can directly connected?

I have a lot of breakpoints, the database should be connected, select statement should be carried out normally, otherwise don't jump to the else inside

CodePudding user response:

reference 1st floor EdsionWang response:
SqlDataReader after use is need to be closed, cmd1 execution ExecuteNonQuery with Dr. Close ();

Wow really sqldatareader did not shut down, I combined with Dr. Close interpolation success, but still shows there are many exceptions, don't know how to return a responsibility

CodePudding user response:

Rookie mistake, reader opening must be closed,

In fact you download a sqlhelper or dbhelper,
Many online, no need to repeat the write sqlconnection and sqlcommand
  • Related