The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Object reference not set to an instance of an object

Last post 08-29-2007, 5:52 AM by Scott.Schecter. 9 replies.
Sort Posts: Previous Next
  •  08-28-2007, 12:02 AM 4805

    Object reference not set to an instance of an object

    We are currently evaluating es and I am stumpted. I have added 5 entries to web.config, one for DNN itself plus one for each of the country specific databases our host will support via multiple portals on the same site. I have also configured global.asax to register the loader. The web site will always use the DNN database for DNN/module specific stuff, but use the specific country's database for application data. The databases are SQL Server and replicated from the target country's local database to the web server and visa versa. Consequently there is no opportunity to place all tables in the one database. Therefore each module needs to interact with data from two databases, depending on whether the data is DNN/Module data or application data. Firstly, I keep getting an error in the module "Object reference not set to an instance of an object" as soon as I try to execute any data retrieval method; LoadByPrimaryKey, LoadAll, etc. I have verified that prior to the read request, the database default has been set to the correct database. I'm not getting anywhere with this due to the lousy degbugging in .NET (the DNN server is not local so cannot use runtime debugging) so any help would be greatly appreciated.

    Extract from web.config

     <sectionGroup name="EntitySpaces" type="EntitySpaces.Interfaces.esConfigSettings, EntitySpaces.Core" >
       <section name="connectionInfo" type="EntitySpaces.Interfaces.esConfigSettings, EntitySpaces.Interfaces" allowLocation="true" allowDefinition="Everywhere" restartOnExternalChanges="true" />
     </sectionGroup>


     <section name="infragistics.web" type="System.Configuration.SingleTagSectionHandler,System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      </configSections>
      <infragistics.web enableAppStyling="true" styleSetPath="~/ig_res/" styleSetName="Default"/>

     <EntitySpaces>
      <connectionInfo default="SQL_au">
       <connections>
        <add name="SQL_DNN"
          providerMetadataKey="esDefault"
          sqlAccessType="DynamicSQL"
          provider="EntitySpaces.SqlClientProvider"
          providerClass="DataProvider"
          connectionString="User ID=dnnuser;Password=XXXX;Initial Catalog=DotNetNuke_dev;Data Source=PromaW2"
          databaseVersion="2005"/>
        <add name="SQL_au"
          providerMetadataKey="esDefault"
          sqlAccessType="DynamicSQL"
          provider="EntitySpaces.SqlClientProvider"
          providerClass="DataProvider"
          connectionString="User ID=proma;Password=XXXX;Initial Catalog=Pro-Ma;Data Source=PromaW2"
          databaseVersion="2005"/>
        <add name="SQL_cad"
          providerMetadataKey="esDefault"
          sqlAccessType="DynamicSQL"
          provider="EntitySpaces.SqlClientProvider"
          providerClass="DataProvider"
          connectionString="User ID=proma;Password=XXXX;Initial Catalog=Canada;Data Source=PromaW2"
          databaseVersion="2005"/>
        <add name="SQL_nz"
          providerMetadataKey="esDefault"
          sqlAccessType="DynamicSQL"
          provider="EntitySpaces.SqlClientProvider"
          providerClass="DataProvider"
          connectionString="User ID=proma;Password=XXXX;Initial Catalog=NZ;Data Source=PromaW2"
          databaseVersion="2005"/>
        <add name="SQL_uk"
          providerMetadataKey="esDefault"
          sqlAccessType="DynamicSQL"
          provider="EntitySpaces.SqlClientProvider"
          providerClass="DataProvider"
          connectionString="User ID=proma;Password=XXXX;Initial Catalog=UK;Data Source=PromaW2"
          databaseVersion="2005"/>
       </connections>
      </connectionInfo>
     </EntitySpaces>

    Contents of global.asax

    <%@ Application Inherits="DotNetNuke.Common.Global" Language="VB" %>

    <script runat="server">

    sub Application_Start(sender as object, e as EventArgs)
     EntitySpaces.Interfaces.esProviderFactory.Factory = New EntitySpaces.LoaderMT.esDataProviderFactory
    end sub

    </script>

     

    Extract from module getting error

       Dim Product As New Products
       Product.es.Connection.Name = "SQL_au"
       Product.LoadByPrimaryKey(esSqlAccessType.DynamicSQL, "10522")   <-- Error

    PLEASE HELP!!!

  •  08-28-2007, 12:10 AM 4806 in reply to 4805

    Re: Object reference not set to an instance of an object

    When you generated your classes with the Generated master template, did you check Ignore Schema and Ignore Catalog on the advanced tab?
    David Neal Parsons
    www.entityspaces.net
  •  08-28-2007, 4:31 AM 4809 in reply to 4806

    Re: Object reference not set to an instance of an object

    Also, make sure you are putting the proper EntitySpaces data providers into your bin folders? The lastest Trial, 0819 no longer just gives the "Object Reference not set error" but instead gives meaningful errors that can really tell you what exactly the problem is.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-28-2007, 3:21 PM 4830 in reply to 4806

    Re: Object reference not set to an instance of an object

    When I generated the classes using the generated master template, I did check the Igenore Schema and Ignore Catalog on the advanced tab, as documented.  However, I have tried it both ways and get the same result either way. .... very frustrating!!

  •  08-28-2007, 3:31 PM 4832 in reply to 4809

    Re: Object reference not set to an instance of an object

    The latest version 0819 is not posted on the Trial Download page......  I would like to test with this version - any chance of making it available on the trial?
  •  08-28-2007, 3:56 PM 4834 in reply to 4832

    Re: Object reference not set to an instance of an object

    We no longer require registration or login to get the latest Trial. Just click the "Install the EntitySpaces 2007 Trial Version" button on the Home page. It will take you to a download page that is the latest 0819.
    David Neal Parsons
    www.entityspaces.net
  •  08-28-2007, 8:44 PM 4848 in reply to 4834

    Re: Object reference not set to an instance of an object

    I have more information.....

    The Global.asax file which resides in the root folder of the DNN application contains:-

    <%@ Application Inherits="DotNetNuke.Common.Global" Language="VB" %>

    <script runat="server">

    sub Application_Start(sender as object, e as EventArgs)
     EntitySpaces.Interfaces.esProviderFactory.Factory = New EntitySpaces.LoaderMT.esDataProviderFactory
    end sub

    </script>

    Now I have installed es version 0819, the error message I get is "No Loader Assigned" which means that the script above for Appliction_Start has not executed.  If I place the code snippet

     EntitySpaces.Interfaces.esProviderFactory.Factory = New EntitySpaces.LoaderMT.esDataProviderFactory

    in the DNN module prior to using es, then I get no error which confirms that the Application_Start code has not executed.  Hunting on the web, I note that Microsift say that the Inherits attribute of the @Application directive instructs the ASP.NET application complier to dynamically compile a new application class.  Is the problem then that once that class has been compiled, that all code after that (ie Application_Start()) is being ignored?  If so, then how in DNN do you define the Global.asax to Inhertit the required DNN code, but also have the required EntitySpaces initialization of the loader done?

  •  08-28-2007, 9:00 PM 4849 in reply to 4848

    Re: Object reference not set to an instance of an object

    I am not sure about your Global.asax question in the context of your DNN setup. You could set a break point on Application_Start and see if the code is being hit. My guess is it is not, and thus you get the no loader exception. You could just call all the connection code, and assign the loader dynamically. This is what I typically do as DNN was designed for modular software development, not site wide applications.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  08-28-2007, 10:49 PM 4850 in reply to 4849

    Re: Object reference not set to an instance of an object

    DNN requires that the Global.asax file has Inherits="DotNetNuke.Common.Global".  As discussed in my previous post, this causes ASP.NET to compile this code.  Without DNN, the Inherits clause is not required and there is no problem with the Application_Start() code.  That's the context of the DNN setup.

    I cannot execute the code in Global.asax via the debugger since it is running on a remote server and my localhost doesn't have DNN runtime on it, so I cannot trace the code.  I am just asking the general DNN/EntitySpaces community at large, how do you get around this apparent problem with the Inherits clause?  I'm sure someone out there is using DNN and has modified the Global.asax file to work with DNN and EntitySpaces.....

    In the meantime, I have added the loader assignment to the module page_load event which works around the problem, but doesn't solve it.  I would just like to know the correct solution.

  •  08-29-2007, 5:52 AM 4860 in reply to 4850

    Re: Object reference not set to an instance of an object

    What that directive means is that the code for Global.asax is compiled in

    public sealed class Globals
    
    Name: DotNetNuke.Common.Globals

    Upon further research DNN has a who slew of code in there, and you would have to add your code in said sealed class and recompile the DotNetNuke.dll for your code to be executed. Now, as I said I think this is a horrible approach for DNN development. DNN modules should be modular by design, you should also never have to edit the core code. If you choose to modify the core code you will have a nightmare of an upgrade path trust me. Here is another related post you might find helpful. I would also recommend you copy down your DNN db and filesystem locally so you can debug while you develop without that your are going to be just a blind man in the dark. Hope that clears it up for you...


    Regards,

    Scott Schecter
    EntitySpaces | My Site
View as RSS news feed in XML