2012-07-10 89 views
-3

我已經託管我的應用程序到IIS -7,它瀏覽正確,但它現在讓我登錄,desipte我已檢查它有一個正確的連接字符串,它會在我的日誌頁上引發錯誤爲什麼iis主機應用程序不允許登錄?

描述:An在執行當前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... 
+0

你忘了告訴我們_what_錯誤時拋出。運行時值是什麼時候拋出的。 – David 2012-07-10 10:06:25

+0

當我用某個用戶名,密碼登錄時,它在第8行出現throwsx錯誤。 – NoviceToDotNet 2012-07-10 10:07:37

+1

錯誤非常明顯,「對象引用未設置爲對象的實例」。由於它發生在第98行,因此'_userDetails'或'Rows'都是'null'。我的猜測是'_userDetails'是'null'。在這種情況下,您的'Data.GetSQLQueryResults()'方法被破壞,因爲返回'null'是一個壞主意。無論哪種方式,這不是你的問題所在。您需要修復該功能(可能還有很多其他代碼)來報告遇到的問題,以便確定哪些問題。 – David 2012-07-10 10:10:07

回答

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

你傳入arrParams在它零個元素,您的查詢可能會想到一些參數,返回結果。您現在正在獲取_userDetails的空值。您可以防止異常通過把檢查空上_userDetails

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

} 

要找出確切病因

if (_userDetails != null) 
{ 
    //No data table returned 
    if(_userDetails.Rows.Count != 0) 
    { 
     //No record found 
    } 
} 
相關問題