1

I am use Database MySQL in ASP.NET c# application.When I use simple Steps for connect the MySQL database and create ADO.NET connections working fine. But I want to use Microsoft Enterprise Library for my application.I added Reference given below

  1. Microsoft.Practices.EnterpriseLibrary.Common
  2. Microsoft.Practices.EnterpriseLibrary.Data
  3. Microsoft.Practices.EnterpriseLibrary.Data.S
  4. MySql.Data
  5. MySql.Web

Below is my web.comfig code

<system.data>
  <DbProviderFactories>
    <remove invariant="MySql.Data.MySqlClient" />
    <add name="MySQL Data Provider"
      invariant="MySql.Data.MySqlClient"
      description=".Net Framework Data Provider for MySQL"
      type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.4.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  </DbProviderFactories>
</system.data>
<dataConfiguration defaultDatabase="db1"></dataConfiguration>
<connectionStrings>  
  <add name="constr" connectionString="Server=localhost;Database=db1;user id=test;persistsecurityinfo=True;" providerName="MySql.Data.MySqlClient;"/>
</connectionStrings>
<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="false" />
  </configSections>

and when I use in code by below code

if (_connectionMode == DatabaseConnectionMode.UseConnectionStringName)
{
   _Database = new DatabaseProviderFactory().Create(_dbConnectionString) as Database;
}

here throw the below error

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

Give me proper solution with reason why this happening.

mason
  • 31,774
  • 10
  • 77
  • 121
kinjal
  • 33
  • 8

1 Answers1

0

Your connection string name needs to match the default database:

<dataConfiguration defaultDatabase="db1"></dataConfiguration>
<connectionStrings>  
  <add name="db1" connectionString="Server=localhost;Database=db1;user id=test;persistsecurityinfo=True;" providerName="MySql.Data.MySqlClient;"/>
</connectionStrings>
Steve Greene
  • 12,029
  • 1
  • 33
  • 54
  • Your solution I applied. And also add "EntLibContrib.Data.MySql" dll for MySQL. Now **"Activation error occured while trying to get instance of type Database, key "** error arise. – kinjal Feb 16 '16 at 05:16
  • What connector version you using (http://stackoverflow.com/questions/22438041/activation-error-occured-while-trying-to-get-instance-of-type-database-key-co) and see this: http://stackoverflow.com/questions/4030436/activation-error-occured-while-trying-to-get-instance-of-type-database-key – Steve Greene Feb 16 '16 at 16:13