Enterprise Library DAAB 6 and ODP.NET - Connection string for the default database 'XXX' does not exist

6.6k views Asked by At

I am using enterprise library DAAB 6. To communicate with Oracle database I am using EntLib Contrib library.

Configuration file of my application looks like

<configuration>
    <configSections>
        <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" />
    </configSections>
    <dataConfiguration defaultDatabase="OracleConnectionString">
        <providerMappings>
            <add databaseType="EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Oracle.DataAccess.Client" />
        </providerMappings>
    </dataConfiguration>
    <connectionStrings>
        <add name="OracleConnectionString" connectionString="Data Source=localhost:1521/dev;User ID=db_owner;Password=admin;"
            providerName="Oracle.DataAccess.Client" />
    </connectionStrings>
<configuration>

I have installed all the required packages using NuGet. Package.Config file looks like:

<packages>
    <package id="EnterpriseLibrary.Common" version="6.0.1304.0" targetFramework="net45" />
    <package id="EnterpriseLibrary.Data" version="6.0.1304.0" targetFramework="net45" />
    <package id="EntLibContrib.Data.OdpNet" version="6.0.1304.0" targetFramework="net45" />
</packages>

I have also added a reference to the Oracle.DataAccess.dll file.

I connect to the database using the following line of code

var database = new DatabaseProviderFactory().CreateDefault();

The above line generates a very weird error message. Full stack trace is given below:

System.InvalidOperationException: The connection string for the default database 'OracleConnectionString' does not exist or does not have a valid provider. 
---> System.Configuration.ConfigurationErrorsException: The requested database OracleConnectionString does not have a valid ADO.NET provider name set in the connection string. (C:\Test\OraConsole\bin\Debug\OraConsole.vshost.exe.Config line 13)
   at Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings.GetDatabase(String name)
   at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseProviderFactory.DatabaseConfigurationBuilder.<CreateDefault>b__2(String n)
   --- End of inner exception stack trace ---
   at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseProviderFactory.DatabaseConfigurationBuilder.<CreateDefault>b__2(String n)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseProviderFactory.DatabaseConfigurationBuilder.CreateDefault()
   at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseProviderFactory.CreateDefault()
   at Data.OdpNet.QuickStarts.Console.Program.Main(String[] args) in c:\Test\OraConsole\Program.cs:line 15

tnsping is working fine for the Oracle database.

I have googled this particular error message but I am unable to find the solution for this problem. I have also tried the QuickStart code sample available with Contrib source. Its also generating the same error message.

1

There are 1 answers

0
Randy Levy On BEST ANSWER

It sounds like DbProviderFactories is not setup for Oracle. Usually when installing ODP.NET the machine config will get updated with something like:

<system.data>
    <DbProviderFactories>
      <add name="Oracle Data Provider for .NET Version 11.1.0.6.0"
           invariant="Oracle.DataAccess.Client Version 11.1.0.6.0"
           description="Oracle Data Provider for .NET Version 11.1.0.6.0"
           type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess,
           Version=2.111.6.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
</system.data>

See ODP.NET Configuration. I would verify the machine.config is setup. You could also set up the provderfactories in your app/web.config.