AndeeC
AndeeC

Reputation: 407

The requested database does not have a valid ADO.NET provider name set in the connection string

I am trying to connect my C# application to an oracle database using Oracle.ManagedDataAccess. However, when I try to create the database it gives me the error below. Any ideas as to what I'm setting up incorrectly? I know that the provider name is set correctly, because I'm able to connect to the database exactly the same way with another C# application.

"The requested database ConnectionString.SomeName does not have a valid ADO.NET provider name set in the connection string"

On machine.config:

<add name="ConnectionString.SomeName" providerName="Oracle.ManagedDataAccess.Client" connectionString="Data Source=databaseSource;User Id=some_id;Password=some_password" />

On web.config:

<appSettings>
  <add key="ConnectionString1" value="ConnectionString.SomeName"/>
</appSettings>

My code:

DatabaseProviderFactory factory = new DatabaseProviderFactory();
Database = factory.Create(ConfigurationManager.AppSettings["ConnectionString1"]);

Upvotes: 0

Views: 7845

Answers (3)

BA TabNabber
BA TabNabber

Reputation: 1356

The solution that worked for me is to add the following to the App.config / Web.config (within the configuration tag):

  <system.data>
    <DbProviderFactories>
      <remove invariant="Oracle.ManagedDataAccess.Client" />
      <add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
  </system.data>

Upvotes: 0

SaraNa
SaraNa

Reputation: 76

The 'key' in your appSettings entry should match the 'name' in your connectionStrings entry. For example, in your case, you should have this entry in appSettings:

<add key="ConnectionString.SomeName" value="Data Source=dataSource;User ID=some_id;Password=some_password" />

Upvotes: 1

Zombie012345
Zombie012345

Reputation: 26

In the Machine.config, check to ensure that you have two sections setup. One in " and another in . Examples below:

    <appSettings>
    <add key="ConnectionString.SomeName" value="Data Source=databaseSource;User Id=some_id;Password=some_password"/>
</appSettings>

<connectionStrings>
    <add name="ConnectionString.SomeName" connectionString="Data Source=databaseSource;User Id=some_id;Password=some_password" providerName="Oracle.DataAccess.Client"/>
</connectionStrings>

Upvotes: 1

Related Questions