MarcoMySql DataProvider

di Marco Leoncini, in ASP.NET 2.0,

English version

MarcoMySql è la rifattorizzazione del Data Provider per MySql (Connector 1.0.7) al fine di implementare le classe basi contenute nel namespace System.Data.Common.

La rifattorizzazione comprende l'aggiornamento di alcune classi e l'implementazione della nuova classe factory MySqlProviderFactory (MySql.Data.MySqlClient).
La classe MySqlProviderFactory ci consente di utilizzare MySql insieme al controllo SqlDataSource.

Una volta copiata la dll nella cartella \bin\, è sufficente aggiungere nel Web.Config le seguenti righe:

&lt;system.data&gt;<br />  &lt;DbProviderFactories&gt;<br />    &lt;add name=&quot;MarcoMySql Data Provider&quot; invariant=&quot;MySql.Data.MySqlClient&quot; description=&quot;Marco MySql Provider&quot; type=&quot;MySql.Data.MySqlClient.MySqlProviderFactory, MarcoMySql.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&quot; /&gt;<br />    &lt;/DbProviderFactories&gt;<br />&lt;/system.data&gt;

Potremo infine aggiungere ad esempio un SqlDataSource collegato ad una GridView, così configurato sulla nostra pagina, che funzionerà al 100% con MySQL, prestando particolare attenzione a impostare il nome del Provider su "MySql.Data.MySqlClient":

&lt;asp:SqlDataSource ID=&quot;SqlDataSource1&quot; runat=&quot;server&quot; ConnectionString=&quot;Server=localhost;Uid=root;Pwd=X;Database=aspitalia;&quot;<br />ProviderName=&quot;MySql.Data.MySqlClient&quot; SelectCommand=&quot;select ID, Name, Address from Customer&quot;<br />InsertCommand=&quot;INSERT INTO customer VALUES(null, ?name, ?address)&quot; <br />DeleteCommand=&quot;DELETE FROM customer WHERE ID = ?ID &quot;<br />UpdateCommand=&quot;UPDATE customer SET name=?name, address=?address WHERE ID = ?ID;&quot;&gt;<br />  &lt;InsertParameters&gt;<br />    &lt;asp:ControlParameter ControlID=&quot;TextBoxName&quot; ConvertEmptyStringToNull=&quot;true&quot; Name=&quot;name&quot; /&gt;<br />    &lt;asp:ControlParameter ControlID=&quot;TextBoxAddress&quot; ConvertEmptyStringToNull=&quot;true&quot; Name=&quot;address&quot; /&gt;<br />  &lt;/InsertParameters&gt;<br />&lt;/asp:SqlDataSource&gt;

Si puossono scaricare direttamente sorgenti ed assembly.

English version

MarcoMySql is a MySql (Connector 1.0.7) Data Provider compliant with the new classes required by System.Data.Common and the new Factory architecture of ADO.NET.

This release includes new updated classes and a brand new MySqlProviderFactory class(MySql.Data.MySqlClient).
MySqlProviderFactory allows you to use MySql with a SqlDataSource control.

You have to deploy the file in the \bin\ directory and add this rows to your Web.Config file:

&lt;system.data&gt;<br />  &lt;DbProviderFactories&gt;<br />    &lt;add name=&quot;MarcoMySql Data Provider&quot; invariant=&quot;MySql.Data.MySqlClient&quot; description=&quot;Marco MySql Provider&quot; type=&quot;MySql.Data.MySqlClient.MySqlProviderFactory, MarcoMySql.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&quot; /&gt;<br />    &lt;/DbProviderFactories&gt;<br />&lt;/system.data&gt;

Now you can add a SqlDataSource control bound to a GridView one, that will work the same way as using SQL Server, setting the Provider property on "MySql.Data.MySqlClient":

&lt;asp:SqlDataSource ID=&quot;SqlDataSource1&quot; runat=&quot;server&quot; ConnectionString=&quot;Server=localhost;Uid=root;Pwd=X;Database=aspitalia;&quot;<br />ProviderName=&quot;MySql.Data.MySqlClient&quot; SelectCommand=&quot;select ID, Name, Address from Customer&quot;<br />InsertCommand=&quot;INSERT INTO customer VALUES(null, ?name, ?address)&quot; <br />DeleteCommand=&quot;DELETE FROM customer WHERE ID = ?ID &quot;<br />UpdateCommand=&quot;UPDATE customer SET name=?name, address=?address WHERE ID = ?ID;&quot;&gt;<br />  &lt;InsertParameters&gt;<br />    &lt;asp:ControlParameter ControlID=&quot;TextBoxName&quot; ConvertEmptyStringToNull=&quot;true&quot; Name=&quot;name&quot; /&gt;<br />    &lt;asp:ControlParameter ControlID=&quot;TextBoxAddress&quot; ConvertEmptyStringToNull=&quot;true&quot; Name=&quot;address&quot; /&gt;<br />  &lt;/InsertParameters&gt;<br />&lt;/asp:SqlDataSource&gt;

You can freely download the source and the assembly here.

Commenti

Visualizza/aggiungi commenti

| Condividi su: Twitter, Facebook, LinkedIn

Per inserire un commento, devi avere un account.

Fai il login e torna a questa pagina, oppure registrati alla nostra community.

Approfondimenti