MYSQL Connection Error -Data Application Blocks [Resolved]

Posted by Ogipansrk under ASP.NET on 1/21/2012 | Points: 10 | Views : 1592 | Status : [Member] | Replies : 2
Iam using Microsoft Application Block 5.1 for connecting MySql.
But prompts me with below Error

Activation error occured while trying to get instance of type Database, key "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=employee; User=root;Password=root@123;"

MyCode:
-----------
Database dbLst = DatabaseFactory.CreateDatabase();
string strSql = "SELECT * FROM emp";
DbCommand dbCmd = dbLst.GetSqlStringCommand(strSql);
DataSet ProductsDataSet = new DataSet();
ProductsDataSet = dbLst.ExecuteDataSet(dbCmd);
GridView1.DataSource = ProductsDataSet;
GridView1.DataBind();

ConfigFile
------------

<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<dataConfiguration defaultDatabase="mysql" />
<connectionStrings>
<add name="mysql" providerName="MySql.Data.MySqlClient"
connectionString="Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=employee; User=root;Password=root@123;"/>


</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>


</configuration>


Thanks in Advance




Responses

Posted by: Ogipansrk on: 1/23/2012 [Member] Starter | Points: 25

Up
0
Down

Resolved
Problem Solved.
My connectionstring is perfect.
It is the problem with the code.
It doesnot properly support in EntityLib5.0

The following code Works atlast!!

DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);
var db = new GenericDatabase(connectionString, factory);

DbConnection conn = db.CreateConnection();



Ogipansrk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rkworlds on: 1/23/2012 [Member] Starter | Points: 25

Up
0
Down
Local database
Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=employee; User=root;Password=root@123;Option=3;

http://www.connectionstrings.com/mysql#p31

If this helps you .
Please "Mark as Answer"

Ogipansrk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response