Search code examples
sql-serverenterprise-libraryconnection-pooling

Configuring Connection Pool in Microsoft.Practices.EnterpriseLibrary


I am using Data Access Application Block from Microsoft.Practices.EnterpriseLibrary and am finding the online documentation for this aging component lacking.

I'm having an issue with connection pooling and I want to review/adjust the settings for it. However, nothing seems to be mentioned about this in the configuration of the connection string, which is where I would expect it to be configured.

<connectionString name="Sql Connection String">
    <parameters>
        <parameter name="database" value="DB name" isSensitive="false" />
        <parameter name="password" value="xxx" isSensitive="true" />
        <parameter name="server" value="xxx.xxx.xxx.xxx" isSensitive="false" />
        <parameter name="user id" value="xxxxxxxx" isSensitive="false" />
    </parameters>
</connectionString>

Can anyone tell me how I configure connection pooling for this component? Am I even right that is configured in the config file?

I know there is a Windows Forms tool available in connection with Microsoft.Practices.EnterprisesLibrary but I don't have access to this, so I need the direct config file solution.


Solution

  • If you are using file based configuration then Enterprise Library uses the connectionStrings configuration section:

    <connectionStrings>
    
        <add
            name="Sql Connection String" 
            providerName="System.Data.SqlClient"
            connectionString="server=xxx.xxx.xxx.xxx;database=DB name;
    Integrated Security=false;User ID=xxxxxxxx;Password=xxx;Pooling=true;
    Min Pool Size=5;Max Pool Size=20;" />
    
    </connectionStrings>
    

    If you are using fluent configuration it would look something like this:

    var builder = new ConfigurationSourceBuilder();
    
    builder.ConfigureData()
           .ForDatabaseNamed("Sql Database")
             .ThatIs.ASqlDatabase()
             .WithConnectionString("server=xxx.xxx.xxx.xxx;database=DB name;
    Integrated Security=false;User ID=xxxxxxxx;Password=xxx;Pooling=true;
    Min Pool Size=5;Max Pool Size=20;")
             .AsDefault();
    
    var configSource = new DictionaryConfigurationSource();
    builder.UpdateConfigurationWithReplace(configSource);
    EnterpriseLibraryContainer.Current 
      = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);