【发布时间】:2011-08-04 06:07:01
【问题描述】:
我一直在 asp.net 中设计一个网页,我的项目是成功的。我发布了我的网络应用程序。但是,出现以下错误。我该如何清除它?
“/sarav”应用程序中的服务器错误。
对象引用未设置为对象的实例。
说明:在执行当前 web >request 期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误的更多信息以及它在代码中的来源。
异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。
来源错误: 在执行当前 Web 请求期间生成了未处理的异常。 >有关异常来源和位置的信息可以使用 >下面的异常堆栈跟踪来识别。
堆栈跟踪:
[NullReferenceException:对象引用未设置为对象的实例。] Login.btnLogin_Click(Object sender, EventArgs e) +155 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串事件参数)+107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串事件参数)+7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
如何清除错误
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter();
SqlConnection Cnn = new SqlConnection();
DataSet ds = new DataSet();
string constr = null;
SqlCommand cmd = new SqlCommand();
if (IsValid != null)
{
constr = ConfigurationManager.ConnectionStrings["PhotostudioConnectionString"].ConnectionString;
Cnn.ConnectionString = constr;
try
{
if (Cnn.State != ConnectionState.Open)
Cnn.Open();
}
catch (Exception ex)
{
string str1 = null;
str1 = ex.ToString();
}
cmd.Connection = Cnn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "UspGetDataUsrmast";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@usrname", txtUsername.Text);
cmd.Parameters.AddWithValue("@passwrd", txtPassword.Text);
da.SelectCommand = cmd;
try
{
da.Fill(ds);
// cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
string strErrMsg = ex.Message;
//throw new ApplicationException("!!! An Error Occurred While Inserting Record. " + ex.Message);
}
finally
{
da.Dispose();
cmd.Dispose();
Cnn.Close();
Cnn.Dispose();
}
if (ds.Tables[0].Rows.Count > 0)
{
Msg.Text = "Login Successfully";
// da.Dispose();
// cmd.Dispose();
// Cnn.Close();
// Server.Transfer("Home.aspx");
Response.Redirect("PhotosettingsReport.aspx");
}
else
{
Msg.Text = "Login Failed";
}
}
}
}
【问题讨论】:
-
显示一些代码,以便您获得帮助。
-
如果明确你的意思是如何修复这个错误,那么只是为了让你知道它发生了,因为在你的源代码的某个地方你正在使用一个尚未初始化的变量,它必须是btnLogin_登录页面的点击事件
-
你有一个空指针异常,“清除”错误的最佳方法是从你的应用程序中删除错误;)
-
请发布您的 btnLogin_Click 代码。
-
请分享您遇到错误的网页的aspx.cs文件中的一些代码。请确保您分享
Login.btnLogin_Click。
标签: asp.net