<?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>The Infinite Loop - Beginner&#039;s SEO, Beginner C# &#38; JQuery Tutorials &#187; c sharp</title>
	<atom:link href="http://theinfiniteloopblog.com/tag/c-sharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://theinfiniteloopblog.com</link>
	<description>Problem. Problem Solved. Loop. - The life of a programmer</description>
	<lastBuildDate>Wed, 17 Aug 2011 15:29:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Installing and Configuring MySql/Connecting with C#</title>
		<link>http://theinfiniteloopblog.com/dbs/mysql/installing-and-configuring-mysqlconnecting-with-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=installing-and-configuring-mysqlconnecting-with-c</link>
		<comments>http://theinfiniteloopblog.com/dbs/mysql/installing-and-configuring-mysqlconnecting-with-c/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 05:26:06 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[c sharp]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://scottmoniz.com/programmingBlog/?p=42</guid>
		<description><![CDATA[Recently, I was asked to do some C# development with MySQL as the backend. Having C# with SQL Server 2005 development under my belt setting up a connection to a MySQL Server was pretty easy, however, I will walk you through the setup. Two packages you will need are the MySQL Essentials Installer(this installs the [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p>Recently, I was asked to do some C# development with MySQL as the backend.<br />
Having C# with SQL Server 2005 development under my belt setting up a connection to a MySQL Server was pretty easy, however, I will walk you through the setup.</p>
<p>Two packages you will need are the MySQL Essentials Installer(this installs the server)<br />
and the MySQL Connecter/.NET Installer(this installs the bridge between MySQL and .NET)<br />
The third package, the GUI tools, is optional, but it is a lot easier to work with. (Think of it as a Management Studio Express, for those of you who have used SQL 2005)</p>
<p>MySQL Essentials Package: <a title="http://dev.mysql.com/downloads/mysql/5.1.html#downloads" href="http://dev.mysql.com/downloads/mysql/5.1.html#downloads" target="_blank">http://dev.mysql.com/downloads/mysql/5.1.html#downloads<br />
</a>MySqlConnector/NET: <a title="http://www.mysql.com/products/connector/net/" href="http://www.mysql.com/products/connector/net/" target="_blank">http://www.mysql.com/products/connector/net/</a><br />
MySQL Gui Tools: <a title="http://dev.mysql.com/downloads/gui-tools/5.0.html" href="http://dev.mysql.com/downloads/gui-tools/5.0.html" target="_blank">http://dev.mysql.com/downloads/gui-tools/5.0.html</a></p>
<p>Run the Essentials Package first, this package actually contains the server instance.<br />
Follow the prompts, they are pretty much straight forward.<br />
When you receive the prompt about your root password, pick a password.</p>
<p>Next install the MySQL Connector.<br />
Follow the prompts, they are pretty much straight forward as well, and should install pretty quickly.</p>
<p>From here, you can use the command line client located in Start&gt;Program Files&gt;MySql Version&gt;MySql Command Line Client, however, I choose to use the GUI tools instead.<br />
If you have not already, launch the GUI tools installer.</p>
<p>Once this is done, go to Start&gt;Program Files&gt;MySql Version#&gt;MySQL query browser<br />
Click the  ... button next to Stored Connection.<br />
Click New Connection.</p>
<p>Fill out the properties<br />
Connection: Name the connection<br />
Username: root<br />
Password: password used during setup<br />
Hostname: localhost<br />
Port: default is 3306<br />
Schema: specify the default database, you can leave this blank.</p>
<p>Click apply and close.<br />
In the connection screen, from the dropdown, pick the connection we just created.<br />
Type your password.<br />
If given a warning about a default schema, type  test or default in the Default Schema field, this will create<br />
a database named test or default. You can always delete this dummy database afterwards.</p>
<p>To create tables right click your database in the Schemata and click Create New Table.<br />
Most of the GUI is intuitive and should be picked up quite easy.</p>
<p><strong>Connecting to MySQL using C#</strong></p>
<p>Start a C# Application project (I'm using a Console App in my example)<br />
Right click your project and click Add Reference.<br />
Navigate to the Connector DLL.<br />
By default this dll is located at C:/Program Files/MySql/MySql Connector .NET Version#/Binaries/.NET 2.0/MySql.Data.dll</p>
<p>Once this is added add the line:<br />
using MySql.Data.MySqlClient;<br />
using System.Data; //for the ConnectionState enum<br />
to the top of your code.</p>
<p>Add this code to your main/load method:</p>
<p>//sets up the connection string<br />
string connString = "Server = localhost; Database = databaseName; Uid = root; Pwd = pass;";<br />
//creates a new MySqlConnection object<br />
MySqlConnection conn = new MySqlConnection(connString);</p>
<p>try{<br />
//try to open the connection, catch any exceptions<br />
conn.Open();<br />
//if the connection succeeds, print a msg<br />
Console.WriteLine("Connection Succeeded");<br />
}catch(Exception ex){<br />
//print that the connection failed, and the associated Message<br />
Console.WriteLine("Connection Failed: "+ex.Message);<br />
}finally{<br />
//if the connection is currently open, close it<br />
if(conn.State==ConnectionState.Open)<br />
conn.Close();<br />
}</p>
<p><strong>Troubleshooting:</strong></p>
<ul>
<li>If you are having trouble connecting, check your username and password.</li>
<li>Double check the connection string.</li>
<li>If you are sure the above is correct, make sure the MySql server instance is running. You can do this by</li>
<li>going to Start&gt;Run. Type services.msc and hit Ok. Scroll down the list to MySql, it should say started. If it does not, right click and hit Start.</li>
<li>Try to connect with the MySql GUI tools.</li>
</ul>
<p>Just about everything you can do with SQL Server you can do with MySql using the familiarly named classes:<br />
MySqlConnection, MySqlCommand, MySqlDataReader</p>
<p>Hope this gets you started on using MySql and C#.<br />
Any questions or comments, feel free to ask.</p>
]]></content:encoded>
			<wfw:commentRss>http://theinfiniteloopblog.com/dbs/mysql/installing-and-configuring-mysqlconnecting-with-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

