C# mysql 连接错误 "Object reference not set to an instance of an object"

C# mysql connection error "Object reference not set to an instance of an object"

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

namespace ConsoleApplication4
{
class Program
{
    static void Main(string[] args)
    {
        string con = "Server=mysql.2freehosting.com;Database=u772631349_vadi;Uid=u772631349_vadi;password=password";
        MySqlConnection conn = new MySqlConnection(con);
        try
        {
            conn.Open();


        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        } 

        Console.Read();
    }
}

运行 上的这段代码抛出一个异常 "Object reference not set to an instance of am object"...我只是想访问我服务的 mysql 数据库..

您是否尝试过将 uid 替换为用户 ID?

string con = "server=mysql.2freehosting.com;Database=u772631349_vadi;user id=u772631349_vadi;password=password";

不确定这是否是解决方案 - 我觉得没问题。