CodeSmith Community
Your Code. Your Way. Faster!

Are Dynamic Finds Thread Safe?

Latest post 11-01-2007 3:15 AM by swin. 8 replies.
  • 10-25-2007 9:17 AM

    • Nutter
    • Not Ranked
    • Joined on 08-21-2007
    • Nottingham, England
    • Posts 5
    • Points 163

    Are Dynamic Finds Thread Safe?

    Hi,

    Hope someone can help here.

    I'm running a scheduled app to process multiple databases at once. It's designed to be multithreading and for the most part it works fine.

    The problem is that every so often I get the following error when processing one of the databases;

    System.ApplicationException: cannot find the query 'dbo.TransferBids_Find_Dynamic' in the embedded xml file.

       at FootballPro.Data.WorldDatabase.Data.SqlClient.StoredProcedureProvider.GetProcedureBodyFromEmbeddedResource(String name) in [SNIP]WorldDatabase.Data.SqlClient\StoredProcedureProvider.cs:line 161

    This only seems to occour when processing the databases using threads, if they're processed consecutively then the error doesn't appear.

    The code causing it is;

    TransferBidsService bidsService = new TransferBidsService();
    TransferBidsParameterBuilder tbParamBuilder = new TransferBidsParameterBuilder();
    tbParamBuilder.AppendEquals(TransferBidsColumn.Status, ((int)TRANSFERBIDSTATUS.TBS_PENDING).ToString());
    tbParamBuilder.AppendEquals(TransferBidsColumn.PlayerId, Data.PlayerId.ToString());
    TList<TransferBids> outstandingBids = bidsService.Find(tbParamBuilder);

    does anyone have any ideas?

    cheers, Iain

    • Post Points: 35
  • 10-25-2007 10:23 AM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 767
    • Points 22,605

    Re: Are Dynamic Finds Thread Safe?

    What version of the templates are you using (check changes.log)?  I thought that this was resolved in one of the more recent builds.

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 35
  • 10-25-2007 10:37 AM In reply to

    • Nutter
    • Not Ranked
    • Joined on 08-21-2007
    • Nottingham, England
    • Posts 5
    • Points 163

    Re: Are Dynamic Finds Thread Safe?

    .netTiers v2.2.0.603

    • Post Points: 5
  • 10-25-2007 10:47 AM In reply to

    • Nutter
    • Not Ranked
    • Joined on 08-21-2007
    • Nottingham, England
    • Posts 5
    • Points 163

    Re: Are Dynamic Finds Thread Safe?

    The full exception stack trace is:

    System.ApplicationException: cannot find the query 'dbo.TransferBids_Find_Dynamic' in the embedded xml file.

       at SqlClient.StoredProcedureProvider.GetProcedureBodyFromEmbeddedResource(String name) in SqlClient\StoredProcedureProvider.cs:line 161

       at SqlClient.StoredProcedureProvider.GetCommandWrapper(Database database, String commandName, Type columnEnum, SqlFilterParameterCollection parameters, String orderBy, Int32 start, Int32 pageLength) in SqlClient\StoredProcedureProvider.cs:line 204

       at SqlClient.SqlTransferBidsProviderBase.Find(TransactionManager transactionManager, IFilterParameterCollection parameters, String orderBy, Int32 start, Int32 pageLength, Int32& count) in SqlClient\SqlTransferBidsProviderBase.generated.cs:line 324

       at Services.TransferBidsServiceBase.Find(IFilterParameterCollection parameters, String orderBy, Int32 start, Int32 pageLength, Int32& count) in Services\TransferBidsServiceBase.generated.cs:line 547

       at Services.TransferBidsServiceBase.Find(IFilterParameterCollection parameters, String orderBy) in Services\TransferBidsServiceBase.generated.cs:line 508

       at Services.TransferBidsServiceBase.Find(IFilterParameterCollection parameters) in Services\TransferBidsServiceBase.generated.cs:line 496

    If that's any help?

    I've trimmed the full filenames for clarity

    cheers, Iain

    • Post Points: 35
  • 10-25-2007 12:51 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 767
    • Points 22,605

    Re: Are Dynamic Finds Thread Safe?

    Oy....  It looks like the StoredProcedureProvider is not thread safe, even though some attempts have been made to make it so.  Unfortunately, my knowledge of threading and locking issues is pretty scarce, so I don't know how to fix the issue.  Perhaps someone with more threading knowledge can step up and take a look at this class and provide some direction.

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 55
  • 10-26-2007 3:21 AM In reply to

    • Nutter
    • Not Ranked
    • Joined on 08-21-2007
    • Nottingham, England
    • Posts 5
    • Points 163

    Re: Are Dynamic Finds Thread Safe?

    Bah, there goes my hope for an easy fix Smile

     Well, thanks for your help.

     Does anyone know how to fix that?

    cheers,
    Iain

    • Post Points: 35
  • 10-29-2007 10:27 AM In reply to

    • GRAW
    • Top 25 Contributor
    • Joined on 06-23-2006
    • Posts 157
    • Points 4,560

    Re: Are Dynamic Finds Thread Safe?

    Try the patch attached to this post, i think it is caused by the lack of a lock on the indexer property, this simple patch just ensures the hashtables are initialized fully before being accessed.  Please let us know if this fixes your issue, so that it may be incorporated into the release by the .netTiers team. 

    "Small is the number of them that see with their own eyes, and feel with their own hearts" Albert Einstein
    • Post Points: 60
  • 10-31-2007 2:38 PM In reply to

    • Nutter
    • Not Ranked
    • Joined on 08-21-2007
    • Nottingham, England
    • Posts 5
    • Points 163

    Re: Are Dynamic Finds Thread Safe?

    Thanks mate, that seems to have sorted it.

     I'll keep you posted if it happens again.

    cheers,
    Iain

    • Post Points: 35
  • 11-01-2007 3:15 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 925
    • Points 34,785

    Re: Are Dynamic Finds Thread Safe?

    Added as SVN663.

    hth 

    swin 

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 5
Page 1 of 1 (9 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems