我正在開發Asp.net和C#中的學校管理系統。 我創建了一個登錄頁面,當我點擊登錄時發生錯誤oclashred 對象引用未設置爲對象的實例。未將對象引用設置爲ASP.NET中對象的實例
描述:執行當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error:
public string connectionString()
{
string connString = ConfigurationManager.ConnectionStrings["SchoolConnectionString1"].ConnectionString;
return connString;
}
Source File: C:\Users\ALI\Desktop\Final Project\SchoolERP\SchoolERP\Connection\MyConnection.cs Line: 14
我的堆棧跟蹤下
堆棧跟蹤給定:
[NullReferenceException: Object reference not set to an instance of an object.] SchoolERP.Connection.MyConnection.connectionString() in C:\Users\ALI\Desktop\Final SchoolERP.Connection.MyConnection.connectionString() in C:\Users\ALI\Desktop\Final Project\SchoolERP\SchoolERP\Connection\MyConnection.cs:14 SchoolERP.Pages.Membership.Logout.btnLogout_Click(Object sender, EventArgs e) in C:\Users\ALI\Desktop\Final Project\SchoolERP\SchoolERP\Pages\Membership\Logout.aspx.cs:26 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.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
是'ConfigurationManager.ConnectionStrings [「SchoolConnectionString1」]'null'?使用調試器來檢查。如果是這樣,請確保您在'web.config'文件中提供它。在這裏你看到:http://www.connectionstrings.com/store-connection-string-in-webconfig/ –
對象引用錯誤非常簡單。您試圖訪問某個值爲空的變量的屬性。很明顯,它沒有找到你的連接字符串,所以它的值爲null,所以它不能調用'.ConnectionString'屬性。 – paqogomez
你的配置文件似乎缺少連接字符串 –