求助 大家帮帮忙
当zid等于1000时就正常等于1006时就报错等于其他也不正常大家帮忙看看一下是堆栈跟踪
using System;SQL --------------------编程问答-------------------- 以下是堆栈跟踪------------------------------------
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Data.SqlClient;
using KeLin.ClassManager;
public partial class SmsRegister : System.Web.UI.Page
{
private String constr,dbhost,dbuser,dbpass,dbname;
private String Key = null, kid = null, Phone = null, Message = null,SMS_KEY,Nick="新会员";
private int SiteID = 1000;
private int VIP = 0;
private String TJID = null;
//private String siteVIP = null;
protected void Page_Load(object sender, EventArgs e)
{
dbhost = ConfigurationManager.AppSettings.Get("KL_SQL_SERVERIP");
dbuser = ConfigurationManager.AppSettings.Get("KL_SQL_UserName");
dbpass = ConfigurationManager.AppSettings.Get("KL_SQL_PassWord");
dbname = ConfigurationManager.AppSettings.Get("KL_DatabaseName");
constr = String.Format("Data Source={0};Initial Catalog={3};Persist Security Info=True;User ID={1};password={2};", dbhost, dbuser, dbpass, dbname);
if (Request.QueryString["phone"] != null) { Phone = Request.QueryString["phone"].Replace("'", "''").Trim(); }
if (Request.QueryString["mzl"] != null) { Message = Request.QueryString["mzl"].Replace("'", "''").Trim(); }
if (Request.QueryString["ne"] != null) { Nick = Request.QueryString["ne"].Replace("'", "''").Trim(); }
if (Request.QueryString["key"] != null) { Key = Request.QueryString["key"].Replace("'", "''").Trim(); }
if (Request.QueryString["zid"] != null) { SiteID = Int32.Parse(Request.QueryString["zid"].Replace("'", "''").Trim()); }
if (Request.QueryString["zid"] != null) { kid = Request.QueryString["zid"].Replace("'", "''").Trim(); }
if (Request.QueryString["tj"] != null) { TJID = Request.QueryString["tj"].Replace("'", "''").Trim(); }
SqlDataReader Rs = SqlExecute("SELECT * FROM [wap_sms_reg] WHERE siteid="+SiteID);
if (Rs != null)
{
Rs.Read();
if (Rs["isClose"].Equals(1) || Rs["isClose"].Equals(3))
{
SMS_KEY ="100";
Nick = Rs["firstName"].ToString();
}
else {
Response.Write(51);
SMS_KEY ="100";
Nick = Rs["firstName"].ToString();
}
}
else {
Response.Write(551);
}
if (Key == null || Key != SMS_KEY)
{
Response.Write(22);
Response.End();
}
if (Phone == null)
{
Response.Write(123);
Response.End();
}
if (Message == null)
{
Response.Write(12);
Response.End();
}
String name, pass,TjID="";
if (Message.IndexOf("#") > 0)
{
String[] Tmp = Message.Split('#');
if (Tmp[1].Length > 0)
{
TjID = Tmp[1];
}
pass = Phone.Substring(Phone.Length - 4, 4);
}
else
{
pass = Phone.Substring(Phone.Length - 4, 4);
}
name = Nick + Phone.Substring(Phone.Length - 6, 4);
if (pass == "") { Response.Write(4); Response.End(); }
if (name == "") { Response.Write(5); Response.End(); }
Register(SiteID,Phone, name, pass, "admin@wapv.net", TjID);
}
private void Register(int SiteId, String UserName1, String UserNick, String UserPass, String UserMail,String TjID) {
String MaxPerPage_Default, MaxPerPage_Content, sitename, MailServer, MailServerPassWord, moneyregular, sitemoneyname, UserRemark;
UserRemark = "会员";
String filter = "", sitespace = "100",len="0";
SqlDataReader Rsf = SqlExecute("select length,filter,sitespace from domainname where id=1");
if (Rsf != null) {
Rsf.Read();
len = Rsf["length"].ToString();
sitespace = Rsf["sitespace"].ToString();
filter = Rsf["filter"].ToString();
}
Rsf.Close();
Rsf.Dispose();
//读取网站配置
SqlDataReader Rs1 = SqlExecute("select sitename,MaxPerPage_Default,MaxPerPage_Content,MailServer,MailServerPassWord,moneyregular,sitemoneyname from [user] where userid="+SiteId);
if (Rs1!=null)
{
Rs1.Read();
MaxPerPage_Default = Rs1["MaxPerPage_Default"].ToString();
MaxPerPage_Content = Rs1["MaxPerPage_Content"].ToString();
MailServerPassWord = Rs1["MailServerPassWord"].ToString();
MailServer = Rs1["MailServer"].ToString();
sitename = Rs1["sitename"].ToString();
moneyregular = Rs1["moneyregular"].ToString();
sitemoneyname = Rs1["sitemoneyname"].ToString();
Rs1.Close();
Rs1.Dispose();
UserName1 = kid+Phone;
//UserNick = Nick;
SqlDataReader Rs = SqlExecute("SELECT * FROM [user] WHERE username='" + UserName1 + "'");
if (Rs!=null)
{
int lastid = SqlInsert("update [user] set password='" + PubConstant.md5(UserPass).ToLower() + "' where username='" + UserName1 + "'");
//重设密码
if (lastid>0)
Response.Write(33);
}
else
{
String sql1 = "INSERT INTO [user](siteid,username,nickname,password,managerlvl,易做图,age,mobile,money,LastLoginIP,remark,MaxPerPage_Default,MaxPerPage_Content,sitespace,email)VALUES";
String sql = String.Format("{0}({1},'{2}','{3}','{4}','02',1,20,'{2}',{6},'{7}','{8}',{9},{10},'{11}','{12}')",
sql1, SiteId, UserName1, UserNick, PubConstant.md5(UserPass).ToLower(), UserMail, MailServerPassWord, getIp(), UserRemark, MaxPerPage_Default, MaxPerPage_Content, sitespace, UserMail);
int userid = SqlInsert(sql);
if (userid > 0)
{
Response.Write(44); //注册成功
//写站内信
if (MailServer != "")
{
sql = "insert into wap_message(siteid,userid,nickname,title,content,touserid,issystem)values(" + SiteId + "," + SiteId + ",'系统消息','" + sitename + " 欢迎您!','" + MailServer + "'," + userid + ",0)";
SqlInsert(sql);
}
//奖励推荐人
if (TjID != "")
{
String[] t = moneyregular.Split(new Char[] { '|' });
if (t.Length >= 4)
{
moneyregular = t[4];
}
if (moneyregular.IndexOf('|') == -1)
{
sql = "update [user] set money=money+" + moneyregular + " where userid=" + TjID;
SqlInsert(sql);
//发信息给推荐人
sql = "insert into wap_message(siteid,userid,nickname,title,content,touserid,issystem)values(" + SiteId + "," + SiteId + ",'系统消息','新会员 " + UserNick + " 注册成功,你得到" + moneyregular + "个" + sitemoneyname + "奖励!','推荐成功'," + TjID + ",0)";
SqlInsert(sql);
}
}
}
else {
Response.Write(552);//未知错误
}
}
}
else {
//网站没开通
Response.Write(553);
}
}
private int SqlInsert(String sql) {
SqlConnection conn = new SqlConnection(constr);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
int row = cmd.ExecuteNonQuery();
if (row > 0)
{
cmd.CommandText = "SELECT * FROM [user] ORDER BY userid DESC";
object Rs = cmd.ExecuteScalar();
if (Rs != null) {
return Convert.ToInt32(Rs);
}
}
cmd.Dispose();
return 0;
}
catch (Exception ex)
{
Response.Write(ex.Message + "\r\n" + ex.StackTrace + "<br />");
}
finally
{
if (conn.State.Equals("Open")) conn.Close();
}
return 0;
}
private SqlDataReader SqlExecute(String sql)
{
SqlConnection conn = new SqlConnection(constr);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader Rs = cmd.ExecuteReader();
if (Rs.HasRows)
{
cmd.Dispose();
return Rs;
}
else {
return null;
}
}
catch (Exception ex)
{
Response.Write(ex.Message+"\r\n"+ex.StackTrace+"<br />");
}
finally {
if (conn.State.Equals("Open")) conn.Close();
}
return null;
}
private String getIp() {
return Request.UserHostAddress;
}
}
',' 附近有语法错误。 在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) 在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) 在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) 在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() 在 SmsRegister.SqlInsert(String sql)
552 --------------------编程问答-------------------- sql语句的问题。
不知道你报错的是哪一行,检查下对应的sql。
补充:.NET技术 , ASP.NET