gpt4 book ai didi

c# - 无法打印异常字符串,因为 Exception.ToString() 失败

转载 作者:行者123 更新时间:2023-12-05 04:38:46 31 4
gpt4 key购买 nike

我正在尝试连接 MySql 数据库,但在执行代码时出现此错误:

无法打印异常字符串,因为 Exception.ToString() 失败

using System;

using MySql.Data.MySqlClient;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string connStr = "server=localhost;user=root;database=people;password=slidan4eg";

MySqlConnection conn = new MySqlConnection(connStr);

conn.Open();

string sql = "SELECT name FROM men WHERE id = 2";

MySqlCommand command = new MySqlCommand(sql, conn);

string name = command.ExecuteScalar().ToString();

Console.WriteLine(name);

conn.Close();

}
}
}

UPD:我试着调试这个,调试器说程序在 conn.Open(); 上坏了,我认为这可能很重要 enter image description here

最佳答案

根据您的屏幕截图,您有一个 System.IO.FileNotFoundException 并且您缺少 System.Security.Permissions 程序集。您可以使用 Visual Studio 中的 NuGet-PaketManager 来安装它。

关于c# - 无法打印异常字符串,因为 Exception.ToString() 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70521137/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com