C# .NET - what are the procedure to remote mysql database with c#.net

Asked By Babu D
02-Aug-11 04:32 AM


 hai..sir/madam..


          what are the procedure to connect remote(online) mysql database with c#.net.

thank you..
  Vickey F replied to Babu D
02-Aug-11 04:33 AM

You will have to code the connection manually to connect to a remote MySQL database using Visual C# 2008 Express Edition.

VS 2008 Express (and VS 2005 Express too) doesn't allow you to use MySQL .Net Provider through the Data Source Dialog. The non-Express edition allow you to do the same.

To use MySQL in VS Express, you will have to include a reference to the MySQL DLLs. If you have installed the MySQL .Net Provider, the DLLs will be in C:\Program Files\MySQL\MySQL Connector Net x.x.x). Or copy the DLLs to the Bin folder of your project. After including the DLLs, you can make a ConnectionString to connect to the remote MySQL
Database.

The MySQL .Net Provider can be found http://dev.mysql.com/downloads/connector/net/5.2.html

A similar question was asked in thread http://stackoverflow.com/questions/396593/mysql-net-provider-5-2-does-not-show-up-in-data-source-dialog-of-vs-2008-express

  Reena Jain replied to Babu D
02-Aug-11 04:35 AM
Hi,

you can do it like below

Step1 :

Download MySQlConnector for .net from below link
http://dev.mysql.com/downloads/connector/net/5.1.html


Step 2 : Write code like below
/* Code to Fill the DataGridView with Data */
  
MySqlConnection con = new MySqlConnection("Connection String");
con.Open();
MySqlCommand comm = new MySqlCommand("select * from TableName",con);
MySqlDataAdatapter da = new MySqlDataAdapter(comm);
DataTable dt = new DataTable();
da.Fill()
con.Close();
dataGridView1.DataSource = dt;

Also Add Corresponding Namespaces as needed
  Ravi S replied to Babu D
02-Aug-11 04:36 AM
HI

Assuming that you know how to connect to and query a database,

you'll need the following:

  1. The http://dev.mysql.com/downloads/connector/net/5.2.html
  2. The hostname or IP address of the server
  3. A user ID and password to connect with

Add a reference to the MySQL provider. From there, it works just like connecting to a SQL Server box, except the class names are a bit different and some minor SQL dialect is also different.

Of course, if you don't already know how to connect to a database, you'll need to start a bit slower. I'd recommend you Google yourself a http://www.google.com/search?rlz=1C1CHMB_enUS291US303&ie=UTF-8&q=ADO.NET+tutorial.

refer the links  also

http://www.daniweb.com/software-development/vbnet/threads/140526

http://stackoverflow.com/questions/576573/connecting-remote-mysql-database-using-c-net

  Ravi S replied to Babu D
02-Aug-11 04:38 AM
Hi

Here is an example for doing the C# application foe connecting Remote MySQL database. You will have to use System; System.Collections.Generic; System.Linq; System.Text; MySql.Data.MySqlClient;
Code:
namespace ConsoleApplication1 { class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello ...!");
        String conString = "SERVER = localhost; DATABASE = l2emu; User ID = root; PASSWORD = password;";

    MySqlConnection  connection = new MySqlConnection(conString);

        String command = "SELECT * FROM characters";
      MySqlCommand  cmd = new MySqlCommand(command,connection);

MySqlDataReader reader; try { connection.Open(); cmd.ExecuteNonQuery(); reader = cmd.ExecuteReader(); cmd.CommandType = System.Data.CommandType.Text; while (reader.Read() != false) {

    Console.WriteLine(reader["char_name"]);
    Console.WriteLine(reader["level"]);

}

Console.ReadLine();

} catch (MySqlException MySqlError) { Console.WriteLine(MySqlError.Message); }
For doing this program you will have to download the MySQL connection.
  James H replied to Babu D
02-Aug-11 05:03 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace ConsoleApplication1
{
  class Program
 
  { 
    static void Main(string[] args)
    {
      Console.WriteLine("Welcome ...!");
      String conString = "SERVER = localhost; DATABASE = l2emu; User ID = root; PASSWORD = password;";
 
    MySqlConnection  connection = new MySqlConnection(conString);
 
      String command = "SELECT * FROM characters";
      MySqlCommand  cmd = new MySqlCommand(command,connection);
MySqlDataReader reader;
try
{
  connection.Open();
  cmd.ExecuteNonQuery();
  reader = cmd.ExecuteReader();
  cmd.CommandType = System.Data.CommandType.Text;
  while (reader.Read() != false)
  {
 
    Console.WriteLine(reader["char_name"]);
    Console.WriteLine(reader["level"]);
 
  }
 
  Console.ReadLine();
 
}
catch (MySqlException MySqlError)
{
  Console.WriteLine(MySqlError.Message);
}
 
    }
  }
}
here is the example but you must download the mysql connector,
  Anoop S replied to Babu D
02-Aug-11 05:23 AM
You can connect with Remote DataBase same as Connecting with local database, but here you have to specify the Computername or IP Address of Server in Connection string.

use connectionstring tag like this-

<connectionStrings>
  <add
    name="NorthwindConnectionString"
    connectionString="Data Source=serverName or IP Addres;
    Initial Catalog=Northwind;Persist Security Info=True;User
    ID=userName;Password=password"
    providerName="System.Data.SqlClient"
  />
</connectionStrings>

Hope this will help you.
  Radhika roy replied to Babu D
02-Aug-11 10:58 AM

Assuming that you know how to connect to and query a database, you'll need the following:

  1. The http://dev.mysql.com/downloads/connector/net/5.2.html
  2. The hostname or IP address of the server
  3. A user ID and password to connect with

Add a reference to the MySQL provider. From there, it works just like connecting to a SQL Server box, except the class names are a bit different and some minor SQL dialect is also different.

Of course, if you don't already know how to connect to a database, you'll need to start a bit slower. I'd recommend you Google yourself a http://www.google.com/search?rlz=1C1CHMB_enUS291US303&ie=UTF-8&q=ADO.NET+tutorial.

  Radhika roy replied to Babu D
02-Aug-11 10:59 AM
I got solution i this
link- 



http://stackoverflow.com/questions/402355/connect-to-remote-mysql-database-with-visual-c


Try this code-






using
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace ConsoleApplication1
{
   
class Program

   
{




       
static void Main(string[] args)
       
{
           
Console.WriteLine("Welcome ...!");
           
String conString = "SERVER = localhost; DATABASE = l2emu; User ID = root; PASSWORD = password;";

       
MySqlConnection  connection = new MySqlConnection(conString);

           
String command = "SELECT * FROM characters";
         
MySqlCommand  cmd = new MySqlCommand(command,connection);
MySqlDataReader reader;
try
{
    connection
.Open();
    cmd
.ExecuteNonQuery();
    reader
= cmd.ExecuteReader();
    cmd
.CommandType = System.Data.CommandType.Text;
   
while (reader.Read() != false)
   
{

       
Console.WriteLine(reader["char_name"]);
       
Console.WriteLine(reader["level"]);

   
}

   
Console.ReadLine();

}
catch (MySqlException MySqlError)
{
   
Console.WriteLine(MySqlError.Message);
}

       
}
   
}
}


Hope this will help you.
Create New Account
help
ms sql & mysql SQL Server can i run both on the same server? SQL Server Discussions SQL Server (1) MySQL (1) SQL Server Books Online (1) Microsoft sql (1) Online (1) Mindspring
Compound INSERT SELECT FROM WHERE subquery problem MySQL -> SQL Server 2005 conversion SQL Server , SQL, Server, 2005, conversion" / > This SQL language is nuts, just nuts. How does anybody put up with such a crude scripting
SQL Server SQL Server Security Discussions SQL Server (1) Role (1) Privileges (1) Database (1) Hi, The following excerpt is taken from Chapter 5 - Microsoft SQL Server 2000 Security of Microsoft SQL Server 2000 Administrator's Pocket Consultant (ISBN 0-7356-1129
What's the go with sql server SQL Server I was just saying today that sql server is full of silly limitations and I seem to hit on a new one every features with more ways to manipulate things than you can poke a stick at. In sql server we don't even have a full range of date functions (a pretty basic feature
SQL Server Migration Assistant Wizard for ACCESS - can't connect to SQL Server SQL Server Hello - - The Wizard leads me through finding and adding the mdb files, and then shows the following error in the step "Connect to SQL Server 2005": an instance of SQL Server 2005." Relevant information about my SQL Server 2005 version