tags:

views:

4959

answers:

5

I am trying to connect to a remote MySQL database using Visual C# 2008 Express Edition. Is there a way to connect using the editor, or do I have to code the connection manually? The editor has a clear and easy-to-follow wizard for connecting to Microsoft SQL Server and Access databases, but I don't see an easy way to add a remote MySQL datasource. I tried searching the help, but couldn't find anything useful.

Has anyone done this using the editor? Or can point me in a useful direction?

+5  A: 

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 here

A similar question was asked in thread 396593 here

Rishi Agarwal
I couldn't find that question when I looked, thanks. I'm downloading the provider, and will follow up if I have any more questions.
Elie
A: 

The good thing about "express" (or even just "csc") is that even if it doesn't have a designer to help with some things (like setting up the connection string to most useful databases), the core framework is not limited. So you'll probably have to put in the connection string yourself and add a reference to the MySQL/.NET provider, but it should work at runtime, even in debug.

Which is very nice ;-p

Marc Gravell
+1  A: 

EDIT: I didn't check Rishi Agarwal's answer before posting. I think his answer has more insight on the express edition

I am not sure about this and express edition, but you should try MySQL Connector/Net. It works fine with my VS2008 Pro.

m3rLinEz
that is the wizard I was referring to... I don't see the other options, just the first three. I'm installing the MySQL Connector for .NET right now.
Elie
Oh, sorry for the confustion. But the express edition will not have "MySQL Database" in the list as Rishi mentioned. I will remove the image to avoid misunderstanding now.
m3rLinEz
Thanks, that explains a bit. So if I have to connect through code, is there a way for me to link components (e.g. a list or a table) to data in my database graphically? Or will I have to do all of this through code? I'm new to Visual Studio.
Elie
I have little experience with Windows Form. But if your "graphically" mean binding your form's control to some database table through GUI, I think there must be a way. You may search for "custom bindingsource" or ask new question for another expert to answer :)
m3rLinEz
A: 

hi,

i am new in mysql... still now not working woth remote mysql server in odbc driver..

I would recommend that you post a new question with information specific to what you are trying to do.
Elie
A: 

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 ... u must download the mysql connector, search at google for more informations and if u want help.. just add me : [email protected]

good luck members!