DatabaseFactory errors. First it tells me the Database provider factory is not set for static DatabaseFactory

Jan 29, 2015 at 7:36 PM
First it tells me the Database provider factory is not set for static DatabaseFactory, so I add it to a class in my DAL, then it tells me the static DatabaseFactory already has a db provider factory set.the error points to one (of many) DAL class where I added this;
static CaseDB()
{
   DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory()); 
//or inserting my own data here:
DatabaseProviderFactory factory = new DatabaseProviderFactory();
Database db = factory.Create("Northwind");
}
I have gone in circles using forums, I would like to resolve this once and for all.
I use VS 2012, EntLib6 with the data application blocked installed. C# windows app with a 3 layer design. All my DAL classes use the Database db = DatabaseFactory.CreateDatabase();

Please tell me where I need to add the databaseFactory stuff, in the DAL somewhere, In all of my DAL classes?, In my app.config. I do have a dataConfiguration with SQL conn strings set with correct names. I must have incorrect configuration, no matter what I do, it generates errors. Please help!
Feb 4, 2015 at 8:31 PM
You only need to configure the DatabaseProviderFactory once. Usually you would do this at application started. For a web project in global.asax or App_Start depending on the approach you are using and for standalone applications using app.config (and deployed as appname.exe.config). Note that be default any other config files will not be loaded.

I would guess that you probably haven't configured the appropriate configuration file. If you are still having troubles you could upload (OneDrive, etc.) a small self-contained sample project that demonstrates the issue.
Feb 5, 2015 at 7:46 PM
Thank you for the reply. I have set the DatabaseProviderFactory. For now, there are no errors. While debugging, the ExecuteDataSet method in my DAL class generated another error, 'Could not find stored procedure'. My UI and BLL layers were communicating with the DAL just fine a week ago, it was reading my stored procedures ok.
static CaseTypeDB()
        {
            DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory());
        }
public static DataTable GetList()
        {
            DataSet ds = null;
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("CJ_CaseTypeListGet");
            //ExecuteDataSet error generated here
            ds = db.ExecuteDataSet(dbCommand);

            DataTable dt = ds.Tables[0];
            return dt;
        }
I also uploaded my project to OneDrive. I can email you my information. Your reply is much appreciated. No one here knows EntLib6.
Feb 5, 2015 at 7:57 PM
My app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
  <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
  <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
  <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
 </configSections>
 <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
  defaultCategory="General">
  <listeners>
   <add name="trace.log" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    source="SPWindowsForm" formatter="Text Formatter" log="FlatFile TraceListener"
    machineName="." traceOutputOptions="None" />
  </listeners>
  <formatters>
   <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    template="Timestamp: {timestamp}{newline}&#xD;&#xA;Message: {message}{newline}&#xD;&#xA;Category: {category}{newline}&#xD;&#xA;Priority: {priority}{newline}&#xD;&#xA;EventId: {eventid}{newline}&#xD;&#xA;Severity: {severity}{newline}&#xD;&#xA;Title:{title}{newline}&#xD;&#xA;Machine: {localMachine}{newline}&#xD;&#xA;App Domain: {localAppDomain}{newline}&#xD;&#xA;ProcessId: {localProcessId}{newline}&#xD;&#xA;Process Name: {localProcessName}{newline}&#xD;&#xA;Thread Name: {threadName}{newline}&#xD;&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
    name="Text Formatter" />
  </formatters>
  <categorySources>
   <add switchValue="All" name="Logging Application Block">
    <listeners>
     <add name="trace.log" />
    </listeners>
   </add>
  </categorySources>
  <specialSources>
   <allEvents switchValue="All" name="All Events" />
   <notProcessed switchValue="All" name="Unprocessed Category" />
   <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
     <add name="trace.log" />
    </listeners>
   </errors>
  </specialSources>
 </loggingConfiguration>
 <exceptionHandling>
  <exceptionPolicies>
   <add name="Global Policy">
    <exceptionTypes>
     <add name="Exception" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
      postHandlingAction="None" />
    </exceptionTypes>
   </add>
  </exceptionPolicies>
 </exceptionHandling>
 <dataConfiguration defaultDatabase="CJCases" />
 <connectionStrings>
  <add name="CJCases" connectionString="Data Source=vmdolsqldev;Integrated Security=True;"
   providerName="System.Data.SqlClient" />
 </connectionStrings>
 <enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
  <sources>
   <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </sources>
 </enterpriseLibrary.ConfigurationSource>
 <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
    </startup>

</configuration>
Feb 9, 2015 at 2:44 PM
I have the following:
Program.cs is the main entry in app. Is this where I am supposed to add the SetdatabaseFactory?
App.config (posted above) has all my configurations.
Packages.config was installed by Nuget for each project of my project (each layer).

I read on another site you saying something about EntLib6 not bootstrapping the xml config. Would you assist me in how to start that or what I need to do?

I have last used Entlib4 about 6 yrs ago. Some things have changed since. Any help is much appreciated. I use c#, VS2012, design a 3-layer Windows form app.