<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.townx.org" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>townx - Using MySQL with ASP.Net, under Mono on Linux - Comments</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux</link>
 <description>Comments for &quot;Using MySQL with ASP.Net, under Mono on Linux&quot;</description>
 <language>en</language>
<item>
 <title>Thanks man!!, it is very</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-41518</link>
 <description>&lt;p&gt;Thanks man!!, it is very useful.&lt;/p&gt;</description>
 <pubDate>Wed, 07 Sep 2011 21:08:10 -0500</pubDate>
 <dc:creator>Crist</dc:creator>
 <guid isPermaLink="false">comment 41518 at http://www.townx.org</guid>
</item>
<item>
 <title>MySql.Data.dl not in GAC?</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-41296</link>
 <description>&lt;p&gt;is it possible to use MySql.Data.dl from local directory rather than install in &lt;span class=&quot;caps&quot;&gt;GAC&lt;/span&gt;? I am using shared hosting!&lt;/p&gt;</description>
 <pubDate>Wed, 30 Mar 2011 10:08:16 -0500</pubDate>
 <dc:creator>petar petrov</dc:creator>
 <guid isPermaLink="false">comment 41296 at http://www.townx.org</guid>
</item>
<item>
 <title>Thank you</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-41223</link>
 <description>&lt;p&gt;Thank you very much for such a good tutorial.&lt;/p&gt;</description>
 <pubDate>Sun, 06 Feb 2011 12:29:17 -0600</pubDate>
 <dc:creator>melf</dc:creator>
 <guid isPermaLink="false">comment 41223 at http://www.townx.org</guid>
</item>
<item>
 <title>I also came across this</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-40808</link>
 <description>&lt;p&gt;I also came across this problem and found out that instead of using &lt;%@ Import Namespace=&quot;MySql.Data&quot; %&gt; you should use &lt;%@ Assembly name = &quot;MySql.Data&quot; %&gt;&lt;/p&gt;</description>
 <pubDate>Thu, 15 Jul 2010 03:04:56 -0500</pubDate>
 <dc:creator>KAD</dc:creator>
 <guid isPermaLink="false">comment 40808 at http://www.townx.org</guid>
</item>
<item>
 <title>Thanx for the support..</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-40800</link>
 <description>&lt;p&gt;Its a very nice tutorial combining both Mysql and Linux..&lt;/p&gt;</description>
 <pubDate>Thu, 08 Jul 2010 09:40:22 -0500</pubDate>
 <dc:creator>Vaibhav</dc:creator>
 <guid isPermaLink="false">comment 40800 at http://www.townx.org</guid>
</item>
<item>
 <title>Thanks, didn&#039;t know that.</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-40681</link>
 <description>&lt;p&gt;Thanks, didn&#039;t know that.&lt;/p&gt;</description>
 <pubDate>Sat, 29 May 2010 06:56:40 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 40681 at http://www.townx.org</guid>
</item>
<item>
 <title>Easier way to install MySql.Data</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-40614</link>
 <description>&lt;p&gt;On Ubuntu, I think you can get MySql.Data through&lt;/p&gt;

&lt;p&gt;sudo apt-get install libmysql-cil-dev&lt;/p&gt;</description>
 <pubDate>Mon, 17 May 2010 17:55:28 -0500</pubDate>
 <dc:creator>Karl Dickman</dc:creator>
 <guid isPermaLink="false">comment 40614 at http://www.townx.org</guid>
</item>
<item>
 <title>I hope you&#039;ve already solved</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-40202</link>
 <description>&lt;p&gt;I hope you&#039;ve already solved it, however I came across the same situation and thought to post how I&#039;ve solved it. Problem was that Linux is case sensitive, so be aware of what you copy to gac location. For me, renaming downloaded file mysql.data.dll to MySql.Data.dll did the trick (I also had to delete file from /usr/lib/mono/gac/MySql.Data/6.1.3.0__c5687fc88969c44d/ as it did not override somehow (?)).&lt;br /&gt;
Hope this will save some time for others.&lt;br /&gt;
p.s. Thanks for the tutorial, Elliot!&lt;/p&gt;</description>
 <pubDate>Fri, 25 Dec 2009 18:05:41 -0600</pubDate>
 <dc:creator>Mykolas Simutis</dc:creator>
 <guid isPermaLink="false">comment 40202 at http://www.townx.org</guid>
</item>
<item>
 <title>Can&#039;r run the test page.</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-40004</link>
 <description>&lt;p&gt;Elliot,&lt;br /&gt;
I followed your instructions to a &#039;T&#039; but when I do to run the page it gives me a message that it can&#039;t find the MySql.Data assembly.&lt;br /&gt;
I&#039;m running Mono 2.2.2 on Fedora Core 9 with MySql 5.0.5  and MySql Connector/NET 5.2.6.&lt;/p&gt;

&lt;p&gt;Dick Steflik&lt;br /&gt;
Binghamton University&lt;/p&gt;</description>
 <pubDate>Fri, 23 Oct 2009 12:29:14 -0500</pubDate>
 <dc:creator>Dick Steflik</dc:creator>
 <guid isPermaLink="false">comment 40004 at http://www.townx.org</guid>
</item>
<item>
 <title>Page won&#039;t refresh</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-39780</link>
 <description>&lt;p&gt;Well first, thanks for putting this out.  I was able to to get mysql and mono working together on mac os x.  &lt;/p&gt;

&lt;p&gt;There is only one problem.  When I load the example page (with my own db info of course) it loads right the first time but when I make changes and try to refresh it doesn&#039;t change the output.  I have to kill xsp server, restart it, and then refresh the page to the changes to appear.  The of course the problem repeats.  &lt;/p&gt;

&lt;p&gt;Any ideas?&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;</description>
 <pubDate>Thu, 06 Aug 2009 17:35:31 -0500</pubDate>
 <dc:creator>Will</dc:creator>
 <guid isPermaLink="false">comment 39780 at http://www.townx.org</guid>
</item>
<item>
 <title>Notes about Mono</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-38945</link>
 <description>&lt;p&gt;Nice tutorial. It shows how easy to use and manipulate both &lt;span class=&quot;caps&quot;&gt;ASP.N&lt;/span&gt;et and MySQL together as a powerful combination. It seems that if you are using open source under Mono development platform, it will run without problems.&lt;/p&gt;</description>
 <pubDate>Sun, 08 Mar 2009 09:33:24 -0500</pubDate>
 <dc:creator>web designer tutorial</dc:creator>
 <guid isPermaLink="false">comment 38945 at http://www.townx.org</guid>
</item>
<item>
 <title>Hi Dave. On Linux, I</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-38652</link>
 <description>&lt;p&gt;Hi Dave. On Linux, I installed the binary intended for Windows. I imagine you would need to do the same thing for Mac too. Not sure exactly how it works, but Mono can load the required classes from the Windows binary, regardless of &lt;span class=&quot;caps&quot;&gt;OS.&lt;/span&gt;&lt;/p&gt;</description>
 <pubDate>Wed, 17 Dec 2008 15:06:22 -0600</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 38652 at http://www.townx.org</guid>
</item>
<item>
 <title>Using a Windows binary, MySQL Connector/NET</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-38651</link>
 <description>&lt;p&gt;I am running &lt;span class=&quot;caps&quot;&gt;OSX, &lt;/span&gt;but new to that, and was curious about installing a windows binary of the MySQL Connector/NET provider. I would think there would be a compatibility issue. Am I understanding this right that I should install the windows binary of the provider? Please confirm and add any information on this. Thanks.&lt;/p&gt;</description>
 <pubDate>Wed, 17 Dec 2008 12:24:04 -0600</pubDate>
 <dc:creator>Dave</dc:creator>
 <guid isPermaLink="false">comment 38651 at http://www.townx.org</guid>
</item>
<item>
 <title>CodePlex / Licenses</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-38604</link>
 <description>&lt;p&gt;There are plenty of projects on CodePlex with licences other than the MS ones.  If you use code provided by Microsoft that won&#039;t be the issue but there are many other good projects there with fully open licences.  Depends on the project really.&lt;/p&gt;</description>
 <pubDate>Sun, 30 Nov 2008 12:45:42 -0600</pubDate>
 <dc:creator>John</dc:creator>
 <guid isPermaLink="false">comment 38604 at http://www.townx.org</guid>
</item>
<item>
 <title>Query caching in MySQL? Or</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comment-38559</link>
 <description>&lt;p&gt;Query caching in MySQL? Or doing the caching at the &lt;span class=&quot;caps&quot;&gt;ASP.NET &lt;/span&gt;layer? Not something I&#039;ve looked at yet, but interesting question.&lt;/p&gt;</description>
 <pubDate>Wed, 12 Nov 2008 09:49:30 -0600</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 38559 at http://www.townx.org</guid>
</item>
<item>
 <title>Using MySQL with ASP.Net, under Mono on Linux</title>
 <link>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux</link>
 <description>&lt;p&gt;Right, I decided there&#039;s not much point writing more about ASP.Net pages until I can show you how to do something useful with them. So I&#039;m going to dive straight in and install the MySQL connector for ASP.Net, so we can do a bit of database-driven page stuff.&lt;/p&gt;

&lt;h3&gt;Setting up a MySQL database&lt;/h3&gt;

&lt;p&gt;First, you&#039;ll need MySQL. I&#039;m not going to tell you how to install that (depends on your Linux), but hopefully it could be as easy as it was for me on Ubuntu:&lt;/p&gt;

&lt;pre&gt;
sudo apt-get install mysql-server mysql-client
&lt;/pre&gt;

&lt;p&gt;How you create your database and users is up to you. I like &lt;a href=&quot;http://dev.mysql.com/downloads/gui-tools/5.0.html&quot;&gt;MySQL Query Browser&lt;/a&gt; and &lt;a href=&quot;http://www.phpmyadmin.net/home_page/index.php&quot;&gt;phpMyAdmin&lt;/a&gt;. The latter needs PHP and a web server; but MySQL Query Browser is a standalone desktop application. If you want to do this in a tutorial style via the command line, you can run these once you&#039;ve installed the MySQL server and client packages:&lt;/p&gt;

&lt;pre&gt;
$ mysql -uroot -p
...

mysql&gt; CREATE DATABASE cdcat;
Query OK, 1 row affected (0.10 sec)

mysql&gt; USE cdcat;
Database changed

mysql&gt; CREATE TABLE artist ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) );
Query OK, 0 rows affected (0.09 sec)

mysql&gt; INSERT INTO artist VALUES(null, &#039;Wire&#039;);
Query OK, 1 row affected (0.00 sec)

mysql&gt; INSERT INTO artist VALUES(null, &#039;The Fall&#039;);
Query OK, 1 row affected (0.00 sec)

mysql&gt; SELECT * FROM artist;
+----+----------+
| id | name     |
+----+----------+
|  1 | Wire     |
|  2 | The Fall |
+----+----------+
2 rows in set (0.00 sec)

mysql&gt; GRANT SELECT, INSERT, UPDATE, DELETE ON cdcat.* TO cdcat@localhost IDENTIFIED BY &#039;hardpassword&#039;;
Query OK, 0 rows affected (0.12 sec)

mysql&gt; FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.13 sec)
&lt;/pre&gt;

&lt;p&gt;What we&#039;ve done here is setup the first table in a CD catalogue database, namely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Created a new database called &lt;strong&gt;cdcat&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Created a table called &lt;strong&gt;artist&lt;/strong&gt; in that database&lt;/li&gt;
&lt;li&gt;Put two artists into the table&lt;/li&gt;
&lt;li&gt;Created a user called &lt;strong&gt;cdcat&lt;/strong&gt; with SELECT, UPDATE, DELETE and INSERT privileges on all tables in the cdcat database
&lt;li&gt;Made those privileges active&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Installing Connector/Net&lt;/h3&gt;

&lt;p&gt;Now you&#039;ve got a MySQL database server, database, table and user set up, you&#039;ll need the MySQL connector for ASP.Net. You need to download &lt;a href=&quot;http://dev.mysql.com/downloads/connector/net/5.2.html&quot;&gt;Connector/Net&lt;/a&gt; from the MySQL website. The one you need is &lt;a href=&quot;http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-5.2.3-noinstall.zip/from/http://www.mirrorservice.org/sites/ftp.mysql.com/&quot;&gt;Windows Binaries, no installer (ZIP)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once the zip file is downloaded, create a directory somewhere and unzip its contents into it. The file you&#039;re after is in the resulting &lt;code&gt;bin&lt;/code&gt; directory, &lt;code&gt;MySQL.Data.dll&lt;/code&gt;. To install it, use the &lt;code&gt;gacutil&lt;/code&gt; tool included in the Mono installer, which puts it into the right place in your Mono library directory:&lt;/p&gt;

&lt;pre&gt;
gacutil -i /path/to/unzipped/connector/bin/MySQL.Data.dll
&lt;/pre&gt;

&lt;p&gt;If &lt;code&gt;gacutil&lt;/code&gt; isn&#039;t on your path you&#039;ll need to reference it correctly using its full path.&lt;/p&gt;

&lt;h3&gt;Creating a simple page to show data from a table&lt;/h3&gt;

&lt;p&gt;To prove you&#039;ve got everything installed correctly, we&#039;ll create a page to display the contents of the &lt;code&gt;artist&lt;/code&gt; table using one of the standard ASP.Net controls. Like I&#039;ve said before, this isn&#039;t going to be a full ASP.Net tutorial, so I&#039;m not going to try to explain Web Forms and all that jazz: I&#039;m just giving a few examples to help you get the pieces working nicely together. See one of the countless ASP.Net books for more detail. (By the way, if anyone can recommend a half-decent tutorial book for ASP.Net, please let me know, as the ones I&#039;ve looked at are generally good reference works, but lousy tutorials.) I&#039;ll try to put more tutorial material in as I learn more about ASP.Net.&lt;/p&gt;

&lt;p&gt;First, create a file called &lt;code&gt;artists.aspx&lt;/code&gt; inside your project folder.&lt;/p&gt;

&lt;p&gt;Next, put this code into the file and save it:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;%@ Page Language=&quot;C#&quot; %&amp;gt;
&amp;lt;%@ Import Namespace=&quot;System.Data&quot; %&amp;gt;
&amp;lt;%@ Import Namespace=&quot;MySql.Data.MySqlClient&quot; %&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&amp;gt;
&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;CD cat&amp;lt;/title&amp;gt;
    &amp;lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&amp;gt;

    &amp;lt;script runat=&quot;server&quot;&amp;gt;
    private void Page_Load(Object sender, EventArgs e)
    {
       string connectionString = &quot;Server=localhost;Database=cdcat;User ID=cdcat;Password=hardpassword;Pooling=false;&quot;;
       MySqlConnection dbcon = new MySqlConnection(connectionString);
       dbcon.Open();

       MySqlDataAdapter adapter = new MySqlDataAdapter(&quot;SELECT * FROM artist&quot;, dbcon);
       DataSet ds = new DataSet();
       adapter.Fill(ds, &quot;result&quot;);

       dbcon.Close();
       dbcon = null;

       ArtistsControl.DataSource = ds.Tables[&quot;result&quot;];
       ArtistsControl.DataBind();
    }
    &amp;lt;/script&amp;gt;

  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Artists&amp;lt;/h1&amp;gt;
    &amp;lt;asp:DataGrid runat=&quot;server&quot; id=&quot;ArtistsControl&quot; /&amp;gt;
  &amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Finally, you need a &lt;code&gt;web.config&lt;/code&gt; file, again in the project root directory. This contains application settings, such as which libraries your application needs. It should contain the following to enable the MySQL libraries to be loaded:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;configuration&amp;gt;
  &amp;lt;system.web&amp;gt;
    &amp;lt;compilation&amp;gt;
      &amp;lt;assemblies&amp;gt;
        &amp;lt;add assembly=&quot;MySql.Data&quot;/&amp;gt;
      &amp;lt;/assemblies&amp;gt;
    &amp;lt;/compilation&amp;gt;
  &amp;lt;/system.web&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Now run your application again with &lt;code&gt;xsp2&lt;/code&gt; from inside the project directory and browse to &lt;a href=&quot;http://localhost:9192/artists.aspx&quot;&gt;http://localhost:8080/artists.aspx&lt;/a&gt;. You should see this:&lt;/p&gt;

&lt;img src=&quot;http://townx.org/files/asp.net.artists.png&quot; /&gt;

&lt;p&gt;I didn&#039;t get to code-behind pages this time. Maybe next time.&lt;/p&gt;</description>
 <comments>http://www.townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux#comments</comments>
 <category domain="http://www.townx.org/tech">tech</category>
 <pubDate>Fri, 03 Oct 2008 16:35:57 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">748 at http://www.townx.org</guid>
</item>
</channel>
</rss>

