Problem running Sample App - DataPortal_Fetch method call failed

Problem running Sample App - DataPortal_Fetch method call failed

Old forum URL: forums.lhotka.net/forums/t/1435.aspx


TravelinMan posted on Tuesday, October 10, 2006

Hello,

I was intrigued and excited by the walkthrough videos Rocky did and decided to dive in and see what I could do. I've gotten the Expert C# book and am trying to run the Project Tracker demo app. I've followed the steps outlined in the Instructions To Build CSLA.NET 2.0 and the ProjectTracker Sample but when I run the PTWeb and select either the Project or Resource options I get the error below.

I ran regsvcs on the EnterpriseServicesHostcs dll and setup the ApplicationRootDirectory in COM+. Also, this is running against SQL 2005 so I modified the connection string to the following:

<add name="PTracker" connectionString= "server=<ServerName>;database=PTracker;uid=PTUser;pwd=PT" providerName="System.Data.SqlClient" />

<add name="Security" connectionString= "server=<ServerName>;database=Security;uid=PTUser;pwd=PT" providerName="System.Data.SqlClient" />

I feel like Im running around in circles for something that might be pretty simple but without knowing yet too much whats under the covers I'm not really sure what else to look for.

If anyone can point me in the right direction I would greatly appreciate it.

Thanks, Mark

[NullReferenceException: Object reference not set to an instance of an object.]

[CallMethodException: DataPortal_Fetch method call failed]

[DataPortalException: DataPortal.Fetch failed (System.NullReferenceException: Object reference not set to an instance of an object.
   at ProjectTracker.Library.Database.get_PTrackerConnection() in C:\csla20cs\ProjectTracker20cs\ProjectTracker.Library\Database.cs:line 14
   at ProjectTracker.Library.ProjectList.Fetch(String nameFilter) in C:\csla20cs\ProjectTracker20cs\ProjectTracker.Library\ProjectList.cs:line 75
   at ProjectTracker.Library.ProjectList.DataPortal_Fetch(Criteria criteria) in C:\csla20cs\ProjectTracker20cs\ProjectTracker.Library\ProjectList.cs:line 64)]
   Csla.DataPortal.Fetch(Type objectType, Object criteria) in C:\csla20cs\csla20cs\Csla\DataPortal\Client\DataPortal.cs:192
   Csla.DataPortal.Fetch(Object criteria) in C:\csla20cs\csla20cs\Csla\DataPortal\Client\DataPortal.cs:140
   ProjectTracker.Library.ProjectList.GetProjectList() in C:\csla20cs\ProjectTracker20cs\ProjectTracker.Library\ProjectList.cs:22
   ProjectList.GetProjectList() in c:\csla20cs\ProjectTracker20cs\www\PTWeb\ProjectList.aspx.cs:88
   ProjectList.ProjectListDataSource_SelectObject(Object sender, SelectObjectArgs e) in c:\csla20cs\ProjectTracker20cs\www\PTWeb\ProjectList.aspx.cs:77
   Csla.Web.CslaDataSource.OnSelectObject(SelectObjectArgs e) in C:\csla20cs\csla20cs\Csla\Web\CslaDataSource.cs:150
   Csla.Web.CslaDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) in C:\csla20cs\csla20cs\Csla\Web\CslaDataSourceView.cs:94
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +41
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360

 

 

twistedstream replied on Wednesday, October 25, 2006

Mark,

I had this same problem to after downloading the new CLSA.NET 2.1 code and running through the instructions PDF to set up the Project Tracker demo.  I'm not sure if this issue only manifests itself on Windows Server 2003, but that's what I'm running as well (not Windows XP or 2000).

The good news is I finally figured it out.

It turns out that the EnterpriseServicesHostcs component is unable to read from the application.config file, as was intended.  The error occurs because the PTrackerConection property of the Database class in the Project Tracker library is attempting to access a connection string (in this case, one named "PTracker") that can't be found.  Why can't it be found?  The main reason is that the code is running within Enterprise Services as a hosted COM+ object.  The host process for Enterprise Services is dllhost.exe, which lives in your system32 directory.  By default, the CLR looks for an application config file by the name of your host process + .config, in this case dllhost.exe.config.  If no such file exists (which in our case it doesn't), then you're left with whatever default configuration the CLR gives you and you certainly don't get anything from the desired application.config file.

I found the solution to this problem here, where it explains how to configure the associated COM+ application to look in a different directory than system32 for a specific file named application.config.  Once you do that, the CLR is able to find your application.config and life is good.

Now, since the application.config and associated application.manifest files are present in the EnterpriseServicesHostcs project in Visual Studio, but not necessarily in the bin\Debug folder, I modified the Copy to Output Directory property of both files from Do not copy (the default) to Copy if newer.  That way I could point the COM+ application at the bin\Debug folder (where the assembly itself lives) instead of the VS project's folder.

Hope this helps.

~pete

 

twistedstream replied on Wednesday, October 25, 2006

By the way, I just noticed that Rocky talks about this exact situation in chapter 12 of his new Expert C# 2005 Business Objects book, starting on page 615.  Rocky also makes the disclaimer in the setup PDF to read that chapter if you decide to use any of the DataPortal proxies besides the local one for further setup instructions.

~pete

TravelinMan replied on Friday, November 03, 2006

Pete

Thanks for the reply. I came upon much the same solution (I am running XP Pro). After I finally figured out which directory I was supposed to point the Application Root directory to everything works fine.

Thanks,

Mark

agohsa replied on Tuesday, November 28, 2006

If you have found a solution to your issue please post it. I ran into the same issue. Thanks.

twistedstream replied on Tuesday, November 28, 2006

I think the solution was posted.  See posts 8312 and 8313 above. 

~pete

agohsa replied on Tuesday, November 28, 2006

Resolved.

Copyright (c) Marimer LLC