3

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 Answers 5

8

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

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.

4 Comments

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.
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.
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.
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 :)
0

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

Comments

0
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,

Comments

0

now u can use entity to mysql http://www.codeproject.com/Tips/426790/Using-MySQL-with-Entity-Framework

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.