3

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
Alex Aza
  • 76,499
  • 26
  • 155
  • 134
Brian Green
  • 567
  • 7
  • 20
  • 1
    Do you have connection string named `ConnectionString` in the config file? – Alex Aza Jun 22 '11 at 02:41
  • Oh, ok. That was it. It generated a connection string that works on my local machine, but not one that would work on a deployed website. Can I uprate comments? – Brian Green Jun 22 '11 at 03:13
  • possible duplicate of [What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net) – John Saunders Jun 22 '11 at 04:00

2 Answers2

6

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

Alex Aza
  • 76,499
  • 26
  • 155
  • 134
4

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>
Martin
  • 39,309
  • 62
  • 192
  • 278