我在 Linq To SQL 数据上下文上遇到空引用异常,我什至不知道从哪里开始

发布于 2024-11-16 11:10:33 字数 1973 浏览 0 评论 0原文

我刚刚将用户和角色 asp 数据库部署到网站,但收到此异常

“对象引用未设置到对象的实例”。 描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

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

Source Error:

Line 41:   #endregion
Line 42:    
Line 43:    public UsersAndRolesDataContext() : 
Line 44:                base(global::System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"    ].ConnectionString, mappingSource)
Line 45:    {


Source File: d:\hosting\7122544\html\SSM\App_Code\UsersAndRoles.designer.cs    Line: 43

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   UsersAndRolesDataContext..ctor() in d:\hosting\7122544\html\SSM\App_Code    \UsersAndRoles.designer.cs:43
   admin_ManageUsers..ctor() in d:\hosting\7122544\html\SSM\admin\ManageUsers.aspx.cs:11
   ASP.admin_manageusers_aspx..ctor() in c:\windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\ssm\5b123e8f\6bb9cf4c\App_Web_tz5adhff.10.cs:0
   __ASP.FastObjectFactory_app_web_tz5adhff.Create_ASP_admin_manageusers_aspx() in     c:\windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\ssm\5b123e8f\6bb9cf4c\App_Web_tz5adhff.12.cs:0
   System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +109
   System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +31
   System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) +37
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +334
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

I just deployed a users and roles asp database to a website and I'm getting this exception

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

Line 41:   #endregion
Line 42:    
Line 43:    public UsersAndRolesDataContext() : 
Line 44:                base(global::System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"    ].ConnectionString, mappingSource)
Line 45:    {


Source File: d:\hosting\7122544\html\SSM\App_Code\UsersAndRoles.designer.cs    Line: 43

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   UsersAndRolesDataContext..ctor() in d:\hosting\7122544\html\SSM\App_Code    \UsersAndRoles.designer.cs:43
   admin_ManageUsers..ctor() in d:\hosting\7122544\html\SSM\admin\ManageUsers.aspx.cs:11
   ASP.admin_manageusers_aspx..ctor() in c:\windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\ssm\5b123e8f\6bb9cf4c\App_Web_tz5adhff.10.cs:0
   __ASP.FastObjectFactory_app_web_tz5adhff.Create_ASP_admin_manageusers_aspx() in     c:\windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\ssm\5b123e8f\6bb9cf4c\App_Web_tz5adhff.12.cs:0
   System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +109
   System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +31
   System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) +37
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +334
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅忆 2024-11-23 11:10:33

您可能在配置文件中缺少名为 ConnectionString 的连接字符串,因此 System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString" ] 返回 null。

You are likely missing connection string, named ConnectionString in the config file, so System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString" ] returns null.

秉烛思 2024-11-23 11:10:33

您的 Web.config 或 App.config 中可能缺少连接字符串。确保您的文件中有类似于以下内容的内容。

<connectionStrings>
    <add name="AdventureWorksEntities" 
         connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl;
         provider=System.Data.SqlClient;provider connection string='Data Source=localhost;
         Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60;
         multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />
</connectionStrings>

You may be missing a connection string in your Web.config or App.config. Make sure that you have something similar to the following in your file.

<connectionStrings>
    <add name="AdventureWorksEntities" 
         connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl;
         provider=System.Data.SqlClient;provider connection string='Data Source=localhost;
         Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60;
         multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />
</connectionStrings>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文