<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PRESOON.COM &#187; ASP.NET</title>
	<atom:link href="http://presoon.com/blog/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://presoon.com/blog</link>
	<description></description>
	<lastBuildDate>Sat, 20 Mar 2010 03:59:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to install ASP.NET with Mysql in Linux server (cPanel)</title>
		<link>http://presoon.com/blog/2009/07/02/aspnet-with-mysql-in-linux-server-cpanel/</link>
		<comments>http://presoon.com/blog/2009/07/02/aspnet-with-mysql-in-linux-server-cpanel/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 03:27:24 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cpanel]]></category>

		<guid isPermaLink="false">http://presoon.com/blog/?p=98</guid>
		<description><![CDATA[Use ASP.NET with Mysql]]></description>
			<content:encoded><![CDATA[<p>You should enable mod_mono in easyapache to enable ASP.NET. However, for using Mysql database with ASP.NET, you need to download and install a connector from Mysql site.<br />
The one you need is <a href="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/">Windows Binaries, no installer (ZIP)</a>.</p>
<p>Installation</p>
<pre><code>cd /usr/local/src/
mkdir asp-connector
cd asp-connector
wget <a href="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/">Windows Binaries, no installer (ZIP)</a>
/opt/mono/bin/gacutil -i  /usr/local/src/asp-connector/bin/MySql.Data.dll</code></pre>
<p><strong>Most of you forget the next step and the Mysql connector won&#8217;t work.</strong></p>
<pre><code>cd /opt/mono/lib/mono/gac/MySql.Data
cd 5.2.3.0__xxxxxxxxxx/
chmod 755 MySql.Data.dll</code></pre>
<p>Restart Apache</p>
<pre><code>/etc/rc.d/init.d/httpd restart</code></pre>
<p>Now you should be able to connect to mysql using .aspx scripts</p>
<p>Here is a custom script to check the working.<br />
First Create a mysql database first (using command line)</p>
<pre><code>$ mysql -u root -p

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

mysql&gt; USE asptest;
Database changed

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

mysql&gt; INSERT INTO testtable VALUES(null,'Fame');
Query OK, 1 row affected (0.00 sec)

mysql&gt; INSERT INTO testtable VALUES(null,'Clean');
Query OK, 1 row affected (0.00 sec)

mysql&gt; SELECT * FROM testtable;
+----+----------+
| id | name |
+----+----------+
| 1 | Fame |
| 2 | Clean |
+----+----------+
2 rows in set (0.00 sec)

mysql&gt; GRANT SELECT, INSERT, UPDATE, DELETE ON asptest.* TO asptest@localhost IDENTIFIED BY 'nogesspassword';
Query OK, 0 rows affected (0.12 sec)

mysql&gt; FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.13 sec)</code></pre>
<p>Lets go to the script<br />
Here is it. It will display the contents of the database.</p>
<p>First, create a file called test.aspx in your web directory<br />
Add this code and save it.</p>
<pre><code>&lt;%@ Page Language="C#" %&gt;
&lt;%@ Import Namespace="System.Data" %&gt;
&lt;%@ Import Namespace="MySql.Data.MySqlClient" %&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
    &lt;title&gt;ASP test&lt;/title&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;

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

       MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM testtable", dbcon);
       DataSet ds = new DataSet();
       adapter.Fill(ds, "result");

       dbcon.Close();
       dbcon = null;

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

  &lt;/head&gt;

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

&lt;/html&gt;</code>
</pre>
<p>Finally, you need a web.config file, in the same web directory where test.aspx . It should contain the following to enable the MySQL libraries to be loaded:</p>
<p>Add the following to web.config</p>
<pre><code>&lt;configuration&gt;
&lt;system.web&gt;
&lt;compilation&gt;
&lt;assemblies&gt;
&lt;add assembly="MySql.Data"/&gt;
&lt;/assemblies&gt;
&lt;/compilation&gt;
&lt;customErrors mode="Off"/&gt;
&lt;/system.web&gt;
&lt;/configuration&gt;</code></pre>
<p>Now try accessing the file test.aspx using http://domainname.com/test.aspx</p>
<p>If you need any help, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://presoon.com/blog/2009/07/02/aspnet-with-mysql-in-linux-server-cpanel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
