Advertise here


Tag cloud


Posts Tagged ‘csharp’

Use MySql with c-sharp .Net

Posted on Tuesday, July 5th, 2011 in Web Development

I’m going to show how to connect, read and update a MySQL database using C-sharp .Net. You can use this for your web applications or other types of C# apps you create.

You can check out how to get your connection string from the app.config for console applications. This also applies for web applications to access the web.config. This will help you better understand the config file and how to access it. But I have made the first method in the code below get the database connection if you already aware of the web.config.

Firstly to access a MySql database you will need to download the MySQL connector dll from MySQL which you reference in your project. Read more


Console C# getting database connection string from app.config file

Posted on Monday, November 1st, 2010 in Top Tips

When writing a console application using C# / .NET and you want to connect to a database, the connection string is typically stored in the app.config file. Below is an example of a web.config which is the same an app.config file used in C#.Net. It is essentially an XML file that stores required data to make your application work. It keeps these bits of data in one place, making it easy to manage when things change. There will be no need to hunt down connection strings or other configuration data with in your application code.

To extend further on this top tip I have written a tutorial on how to use CSharp with MySQL.

 <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
       <ConnectionString>
         <add key="MySQL.DB" value="server=localhost;database=mysqldbname;user=username;password=12345678;" />
       </ConnectionString>

       <system.web>
        <compilation defaultLanguage="c#" debug="true" />
      </system.web>

    </configuration>

To access the connection string the first step would be to make sure that a reference is added to System.Configuration. Then make sure you include it in the class using System.Configuration and the code below is used to access the connection string.To access the connection string the first step would be to make sure that a reference is added to System.Configuration. Then make sure you include it in the class using System.Configuration and the code below is used to access the connection string.

using System.Configuration;

string MysqlConnectionString = ConfigurationManager.ConnectionStrings["dbconnectionstring"].ConnectionString;

This method can also be used to access the app.config file for any web applications.



Web Design Essex | Richard Kotze – Web Technology, Design and Development powered by WordPress | Entries (RSS)