C# ASP.NET MySQL Connection Tutorial with MySQL Connector

View: 2325    Dowload: 0   Comment: 0   Post by: naruto  
Author: none   Category: MySQL   Fields: Computers - Technology

0 point/3 review File has been tested

In order to connect to MySQL Server with .NET in C# or ASP.NET: You need to download MySQL Connector/Net . After you add a reference to your project, it is probably in C:\Program Files\MySQL\MySQL Connector Net 5.0.7\Binaries\.NET 2.0 folder, add the MySql.Data.dll file as a reference. Make your connection string, the following code will shows a standard MySQL connection string.

Introduction

In order to connect to MySQL Server with .NET in C# or ASP.NET:

using MySql.Data.MySqlClient;
public static string GetConnectionString()
{
  string connStr = String.Format("server={0};user id={1}; password={2};" + 
    "database=yourdb; pooling=false", "yourserver",
    "youruser", "yourpass");

  return connStr;
}
MySql.Data.MySqlClient.MySqlConnection mycon = 
  new MySqlConnection( GetConnectionString());
if(mycon .State != ConnectionState.Open)
try
{
  mycon .Open();
}
catch (MySqlException ex)
{
  throw (ex);
}
  • You need to download MySQL Connector/Net .
  • After you add a reference to your project, it is probably in C:\Program Files\MySQL\MySQL Connector Net 5.0.7\Binaries\.NET 2.0 folder, add the MySql.Data.dll file as a reference.
  • Make your connection string, the following code will shows a standard MySQL connection string.
  • Then create an instance from MySql.Data.MySqlClient.MySqlConnection as shown below.
  • Then try to open the MySqlConnection.

So simple as you see, It is always better to do this in data access layer also called DAL.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

C# ASP.NET MySQL Connection Tutorial with MySQL Connector

C# ASP.NET MySQL Connection Tutorial with MySQL Connector Posted on 21-03-2014  In order to connect to MySQL Server with .NET in C# or ASP.NET: You need to download MySQL Connector/Net . After you add a reference to your project, it is probably in C:\Program Files\MySQL\MySQL Connector Net 5.0.7\Binaries\.NET 2.0 folder, add the MySql.Data.dll file as a reference. Make your connection string, the following code will shows a standard MySQL connection string. 5/10 2325

Comment:

To comment you must be logged in members.

Files with category

 

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd