New Posts New Posts RSS Feed: FetchStrategy for StoredProcQuery must be DatasourceOnly
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

FetchStrategy for StoredProcQuery must be DatasourceOnly

 Post Reply Post Reply
Author
hijaggu View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Sep-2010
Posts: 21
Post Options Post Options   Quote hijaggu Quote  Post ReplyReply Direct Link To This Post Topic: FetchStrategy for StoredProcQuery must be DatasourceOnly
    Posted: 25-Oct-2012 at 11:51pm
I am calling certain stored procedure on BOS with FetchStrategy as DatasourceOnly. Even though once in a while it is throwing an exception FetchStrategy for StoredProcQuery must be DatasourceOnly.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 26-Oct-2012 at 5:39am
Hi hijaggu,
 
This exception is thrown when you try to actually se set its FetchStrategy to something other that DataSourceOnly:
 
myStoredProcQuery.QueryStrategy = new QueryStrategy(FetchStrategy.CacheOnly, mgr.DefaultQueryStrategy.MergeStrategy);
 
myStoredProcQuery.With(QueryStrategy.CacheOnly).ExecuteAsync();
 
Any particular reason you are try to set the storeProc FetchStrategy manually?
 
Can you provide a small solution reproducing the issue?
 
Regards,
   sbelini.
Back to Top
hijaggu View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Sep-2010
Posts: 21
Post Options Post Options   Quote hijaggu Quote  Post ReplyReply Direct Link To This Post Posted: 26-Oct-2012 at 8:56am
I was not setting it to any and still it was throwing me an exception. So I have specified it explicitly. My project includes many other projects and third party controls. It would be difficult for me to provide small solution. Also, It doesn't throw this exception consistently. 
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 26-Oct-2012 at 12:49pm
We don't change the StoredProcQuery within our code, so it must be something that is happening externally.
 
You mentioned that you are explicitly setting it. Are you doing it immediatelly before its execution? If not, I'd suggest you do so.
Also, I'd suggest checking the StoredProdQuery's FetchStrategy immediatelly before its execution as a safety check.
 
Back to Top
hijaggu View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Sep-2010
Posts: 21
Post Options Post Options   Quote hijaggu Quote  Post ReplyReply Direct Link To This Post Posted: 06-Nov-2012 at 11:34pm
Here is the syntax which I have been using,

        IEnumerable enumLock = queryGetEntityLock.With ( QueryStrategy.DataSourceOnly ).Execute ();
It throws exception while executing above line and its not throwing exception every time. Once in a while it throws exception and hence it is difficult to reproduce.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 07-Nov-2012 at 11:51am
Are you working with multi threads? i.e. running a background worker or service to run the code above? - this could potentially the the source of the problem.
 
In any case, I will need you to provide a simple solution where the issue happens (even if only sporadically) in order to further investigate this problem.
 
 
Back to Top
hijaggu View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Sep-2010
Posts: 21
Post Options Post Options   Quote hijaggu Quote  Post ReplyReply Direct Link To This Post Posted: 07-Nov-2012 at 4:42pm

 

NO, this code is not being run in a background worker or service. 

It is directly executed as the result of a button click on the UI.

 

Here is a complete sample of the code. 

 

 

    StoredProcQuery queryGetEntityLock = VisiTrackEntityManager.Instance.GetEntityLockQuery ( pObjectId );
 
    // Reduntant just to make sure..  Should default to the EM upon which it was created.
    queryGetEntityLock.EntityManager = VisiTrackEntityManager.Instance;
 
    // Explicitly making sure that we are "DataSourceOnly"
 
    // Why would a server stored procedure ever do otherwise???  How could it?
 
    queryGetEntityLock.QueryStrategy = new QueryStrategy(FetchStrategy.DataSourceOnly, MergeStrategy.OverwriteChanges);
 
    // Just making sure..  Yep, of course it is...
    FPLogger.WriteTrace("Fetch Strategy:" + queryGetEntityLock.QueryStrategy.FetchStrategy, LogEventType.Database);
                
    IEnumerable enumLock = null;
 
    try
    {
        // Execute the stored procedure
        enumLock = queryGetEntityLock.Execute();
    }
    catch (Exception ex)
    {
 
        // Here we get an error!
                    
        // FetchStrategy for StoredProcQuery must be DatasourceOnly.”
 
        FPLogger.WriteException(ex, LogEventType.Database);
                    
    }
 
 
Questions:
 
1)  Why would a Stored Procedure ever need to be told “DataSourceOnly” ?
 
2)  Why would the :Execute() not obey an explicit setting of the .FetchStrategy to “DataSourceOnly”
 
3)  As you can see we are neither accessing nor changing any Entity Manager data or settings.  
We are only executing a stored procedure in the current thread.  
How could this be affected by background thread operations?
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 08-Nov-2012 at 11:18am
 
Thanks for the snippet.
We will use it in an attempt to reproduce the problem to further investigate this.
 
 
You asked:
1)  Why would a Stored Procedure ever need to be told “DataSourceOnly” ?
 
It would never need to be told DataSourceOnly unless explicitly modified previously.
2)  Why would the :Execute() not obey an explicit setting of the .FetchStrategy to “DataSourceOnly”
 
It should not disobey the explicit DataSourceOnly setting. The only possible scenario we could foresee was if you were working with multi threads, which is explained in the next response.
 
 
3)  As you can see we are neither accessing nor changing any Entity Manager data or settings.  We are only executing a stored procedure in the current thread.  How could this be affected by background thread operations?
 
Our hypothesis is that working with the EntityManager across threads could cause this unexpected behavior.
The EntityManager is NOT thread safe and should never be used in such way. (http://drc.ideablade.com/xwiki/bin/view/Documentation/entitymanager-not-thread-safe)
 
Back to Top
hijaggu View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Sep-2010
Posts: 21
Post Options Post Options   Quote hijaggu Quote  Post ReplyReply Direct Link To This Post Posted: 13-Nov-2012 at 10:25am
Hi sbelini,

Any update on this issue. Are you able to reproduce it?
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 13-Nov-2012 at 10:52am
I was not able to reproduce the issue.
 
We will need a solution that reproduces the issue, (even if sporadically) so we can further investigate.
 
Like I previously mentioned, we do not change the fetch strategy of the stored procedure within DevForce code, so there is a high possibility that there is something particular about your code that might be causing it.
 
Once we have a solution that shows the problem, then we can determine the cause.
 
sbelini.
Back to Top
hijaggu View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Sep-2010
Posts: 21
Post Options Post Options   Quote hijaggu Quote  Post ReplyReply Direct Link To This Post Posted: 14-Nov-2012 at 3:36pm

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down