Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
My application was developed in C# and I am using Microsoft.Practices.EnterpriseLibrary.Data to access an MS Access database
when I try to create the database connection get the error below.

"The requested database ConnString does not have provider name set in the connection string."

What am I doing wrong?

My code:
C#
Database db;
DbCommand cmd = null;
db = DatabaseFactory.CreateDatabase("ConnString");


on App.config:


XML
<configuration>
    <connectionStrings>
    <add name="ConnString> connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\DataBase\CDL.accdb ;Persist Security Info=False"/>
    </connectionStrings>
</configuration>
Posted
Updated 29-May-15 3:49am
v2
Comments
[no name] 29-May-15 9:47am    
check your installed accdb version.
Antonio Guedes 29-May-15 10:19am    
I installed the version 12.0.4518.1031 of Microsoft Office Access database engine 2007
Sascha Lefèvre 29-May-15 10:04am    
Try this:

<configuration>
<connectionStrings>
<add name="ConnString" providerName="Microsoft.ACE.OLEDB.12.0" connectionString="Data Source=D:\DataBase\CDL.accdb;Persist Security Info=False;" />
</connectionStrings>
</configuration>
Antonio Guedes 29-May-15 10:16am    
Now the message is:
The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Data.Database, ConexaoAccess]) failed:
Could not find the .NET Framework Data Provider requested.
  It may not be installed. (Strategy type ConfiguredObjectStrategy, index 2)
Sascha Lefèvre 29-May-15 10:49am    
Do you possibly have somewhere else in your code a line where you create a Database-object without specifying the connectionstring-name, like so:

db = DatabaseFactory.CreateDatabase();

?

You need a providerName attribute on your connectionString, which should be set to the name of a .NET Framework data provider. Since you're using an Access database, you probably want the OLEDB provider:
XML
<connectionStrings>
    <add 
        name="ConnString" 
        providerName="System.Data.OleDb"
        connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\DataBase\CDL.accdb;Persist Security Info=False"
    />
</connectionStrings>


Connection Strings and Configuration Files[^]
Don't hard code your DataProviders[^]
 
Share this answer
 
Following the suggestions of Sascha Lefèvre and Richard Deeming, I changed the App.Config for:

XML
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null"/>
  </configSections>
  <dataConfiguration defaultDatabase="ConnString"/>
    <connectionStrings>
        <add name="ConnString" providerName="System.Data.OleDb" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\DataBase\CDL.accdb ;Persist Security Info=False" />
    </connectionStrings>
</configuration>
 
Share this answer
 
XML
<connectionStrings>
   <add name="Connection_String" connectionString="Data Source=MYPC;Initial Catalog=dbtest;Persist Security Info=True;User ID=sa;Password=abc_123456" providerName="System.Data.SqlClient" />
 </connectionStrings>



Just looks like your missing some props. Make sure you add providerName.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900