Unknown Artist
Unknown Artist

Reputation: 153

MicrosoftConfigurationBuilders Connection String Provider Name Error (C#, Oracle)

Web.config is like that.

<configSections>
   <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false"/>
</configSections>



<connectionStrings configBuilders="Environment">
   <add name="ConnectionString" connectionString="ConnectionString" providerName="System.Data.OracleClient" />
   <add name="OracleDbContex" providerName="Oracle.ManagedDataAccess.Client" connectionString="OracleDbContex" />    
</connectionStrings>


<configBuilders>
    <builders>
        <add name="Environment" mode="Greedy" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
    </builders>
</configBuilders>

I have two connection string one of them is normal Ado.net connection. Another one is the oracle entity. But problem is that when program start and connection strings change from environment variables, ado.net connections work normally but dbcontex give this error.

System.InvalidOperationException: 'The connection string 'OracleDbContex' in the application's configuration file does not contain the required providerName attribute."'

If I don't use ConfigurationBuilders, two connection working normally. I need to get connection strings from environment variables. What should I do?

Upvotes: 1

Views: 382

Answers (1)

Unknown Artist
Unknown Artist

Reputation: 153

I found solution. Its about builder mode. I changed greedy to strict and it fixed.

When using Strict mode the configuration values are looked up first and every entry found is updated with override value (if present). Meaning the original connectionString XML node is kept with all its attributes, including the attribute providerName.

Upvotes: 2

Related Questions