VS 2017用户在这里。我正在尝试将C#控制台应用程序连接到MySQL 5.7。但是没有建立连接。一个建议的解决方案是查看未声明的对象,但我不认为这是这种情况。请告知是否。
MySqlConnection conn;
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
public Connection()
{
conn = new MySqlConnection(connStr);
}
<connectionStrings>
<add name="myConnectionString"
connectionString="server=localhostdatabase=store;user=root;
password=pass;port=3306" />
</connectionStrings>
如果我在调试器中运行此操作,我会在conn
上获得以下信息:
IsPasswordExpired' threw an exception of type 'System.NullReferenceException'
ServerThread' threw an exception of type 'System.NullReferenceException'
ServerVersion' threw an exception of type 'System.NullReferenceException'
在这方面几乎找不到,只是密码是在一年前设置的(我真的不相信这会导致这个问题)和一些通过重新安装MySQL服务器来解决它的人。我这样做了,但没有用。
从命令行开始,一切正常。
答案 0 :(得分:0)
如果您确认密码已过期,则可以尝试创建或更改密码:
CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER;
ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER;
您的指南是here。