AsynCallBack BeginInvoke

Topics: Building and extending application blocks, Data Access Application Block, Enterprise Library Core
Mar 25, 2011 at 6:41 AM
 

Hi,

I am using the asyncallback method for asyn call to the c# method in my calass e.g. ClientUsers. My DAL is supported with the Enterprice library. When ever i call to execure or create the database object.

i got the following issue :-

Resolution of the dependency failed,  type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "(none)".
Exception occurred while: while resolving.
Exception is: ThreadAbortException - Thread was being aborted.

-----------------------------------------------
At the time of the exception, the container was:  Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,(none)

 

Any Body help me out

Regards.

Mar 25, 2011 at 8:22 AM

Hi,

Can you post your relevant code and configuration here?

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 25, 2011 at 10:38 AM
Edited Mar 25, 2011 at 10:42 AM

Here is code

 internal delegate void SetupClientMethodDelegate(IClientUser clientUser);

public void SignUp(IClientUser clientUser, SignupType signupType)
        {
            bool result = false;

            try
            {
                result = clientUser.CreateClientUser(signupType);
                //this.AsyncSetupClient(clientUser);
               
            }           
            finally
            {
                if (result)
                {
                    SetupClientMethodDelegate setupClntDel = new SetupClientMethodDelegate(this.AsyncSetupClient);
                    setupClntDel.BeginInvoke(clientUser, new AsyncCallback(this.AsynHandler), null);
                }
            }

        }

    private void AsynHandler(IAsyncResult asynResult)
        {
            SetupClientMethodDelegate myMethodDel;

            try
            {
                object obj = ((AsyncResult)asynResult).AsyncDelegate;
                if (obj != null)
                {
                    myMethodDel = ((AsyncResult)asynResult).AsyncDelegate as SetupClientMethodDelegate;

                    if (myMethodDel != null && asynResult != null)
                        myMethodDel.EndInvoke(asynResult);
                }
            }
            catch (Exception ex)
            {
               
                throw ex;
            }
           

        }
   
        private void AsyncSetupClient(IClientUser clientUser)
        {

                       //This method is asynchoronously called and communicates with DataBase.
                    clientUser.SetupClientDataBase();

        }

 

Here is Configuration so far

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 
    <configSections>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
 
   
 

    <dataConfiguration defaultDatabase="ConnectionString" />
 
    <connectionStrings>
     
        <add name="ConnectionString" connectionString="Data Source=xyp;Initial Catalog=abc;User ID=aaaa;Password=bb;"
            providerName="System.Data.SqlClient" />
     
        <add name="OracleConnectionString" connectionString="Data Source=xyz;Initial Catalog=dd;User ID=dsaaa;Password=saaaa;"
            providerName="System.Data.OracleClient" />
     
     
    </connectionStrings>
 
</configuration>

Mar 26, 2011 at 1:20 PM
Edited Mar 28, 2011 at 2:31 AM

Hi,

You need to add Asynchronous Processing=true (or just async=true) on your connectionstring to use asynchronous method over the connection. Your connectionstring will look like this:

<add name="ConnectionString" connectionString="async=true;Data Source=xyp;Initial Catalog=abc;User ID=aaaa;Password=bb;"
            providerName="System.Data.SqlClient" />

Hope this helps!

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 29, 2011 at 7:48 AM

Thanks for ur reply, this is supporting some what and with this i could get into the real issue.  One more thing i need to ask that, i am using SMO objects to connect to server to run ddls etc.

This area is still creating problem, because its connection is still not asyn=true, i need to know how i can connect to sqlserver instance through SMO using a asyn connection as well.

 

 

Regards.

Mar 29, 2011 at 8:02 AM

We'll have to direct you to post the inquiry regarding SMO on other .NET forums since this is not an EntLib issue.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com