简体   繁体   中英

MySQL C# connection to localhost:'System.NullReferenceException'

VS 2017 user here. I'm trying to connect a C# console app to MySQL 5.7. However there is no connection established. A suggeste solution is to look at undeclared objects, but I do not think that is the case here. Pls advise if it is.

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>

If I run this in the debugger I get the follow information on 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'

There is very little to be found on this, just that the password was set one year ago (I do not really believe that is causing this problem) and some guy that solved it by reinstalling MySQL server. I did that, to no avail.

From the command line everything is working fine.

If you are confirmed that your password expires, you can try to create or alter:

CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER;
ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER;

Your Guide is here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM