链接Mysql小测试

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;

namespace Csharp链接数据库Mysql
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectStr = "server = 127.0.0.1;port = 3306;database = mygamedb;user=root;password=*********";
            MySqlConnection conn = new MySqlConnection(connectStr);
            try
            {
                conn.Open();
                Console.WriteLine("已经建立链接");
            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                conn.Close();
            }

            Console.ReadKey();
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/krystalstar/p/10720088.html
0条评论
添加一条新回复