-3

我已经将我的应用程序托管到 IIS -7 并且它可以正常浏览但它现在不允许我登录,因为我已经检查它有正确的连接字符串,它在我的日志页面上抛出错误

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Line 96:         SqlParameter[] arrParams = new SqlParameter[0];
Line 97:         _userDetails = Data.GetSQLQueryResults(sqlQuery, 0, arrParams);
Line 98:         if (_userDetails.Rows.Count != 0)
Line 99:         {
Line 100:            _userAccountID = _userDetails.Rows[0]["UserAccountID"].ToString();


Source File: d:\Projects\June 20\CorrDefensev2\App_Code\UserInfo.cs    Line: 98 

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   UserInfo.setUserData(MembershipUser membershipUser) in d:\Projects\June 20\CorrDefensev2\App_Code\UserInfo.cs:98
   UserInfo..ctor(String username) in d:\Projects\June 20\CorrDefensev2\App_Code\UserInfo.cs:76
   Account_Login.Login1_LoggingIn(Object sender, LoginCancelEventArgs e) in d:\Projects\June 20\CorrDefensev2\MyPublic\Login.aspx.cs:76
   System.Web.UI.WebControls.Login.OnLoggingIn(LoginCancelEventArgs e) +115
   System.Web.UI.WebControls.Login.AttemptLogin() +85
   System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +125
   System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +177
   System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563



the solution: all i had to use sql server authentication that is a connection string in web.config with the username, password, and it works fantastic...
4

1 回答 1

0
 SqlParameter[] arrParams = new SqlParameter[0];
 _userDetails = Data.GetSQLQueryResults(sqlQuery, 0, arrParams);

您正在传递其中包含零个元素的 arrParams,您的查询可能需要一些参数来返回结果。正如您现在所得到的那样,您有可能为 _userDetails 设置了 null 值。您可以通过在 _userDetails 上检查 null 来防止异常

if (_userDetails != null && _userDetails.Rows.Count != 0)
{

}

找出确切原因

if (_userDetails != null)
{
   //No data table returned
   if( _userDetails.Rows.Count != 0)
   {
        //No record found
   }
}
于 2012-07-11T07:22:41.507 回答