Connect to remote MySQL database with Visual C#

前端 未结 5 760
花落未央
花落未央 2021-01-20 19:39

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 manua

相关标签:
5条回答
  • 2021-01-20 20:14

    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

    0 讨论(0)
  • 2021-01-20 20:17
    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,

    0 讨论(0)
  • 2021-01-20 20:21

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

    0 讨论(0)
  • 2021-01-20 20:26

    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

    0 讨论(0)
  • 2021-01-20 20:29

    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.

    0 讨论(0)
提交回复
热议问题