0

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.

8
  • 1
    Possible duplicate of What is a NullReferenceException, and how do I fix it? Commented Sep 28, 2017 at 21:42
  • sorry, the second public Connection() shouldnt be there Commented Sep 28, 2017 at 21:42
  • 1
    thanks progman for the reference, but the cause stated there are generally objects not declared before used, I do not believe that is the case here. Commented Sep 28, 2017 at 21:48
  • 1
    It's possible the connection string is invalid. It appears to be missing a semi-colon between the server name and database connectionString="server=localhost;database=store;user=root; password=pass;port=3306" Commented Sep 28, 2017 at 21:52
  • The code is not following best practice anyway: the connection should be instantiated each time it is going to be used and then disposed of immediately afterwards. The using construct is useful for that. Commented Sep 28, 2017 at 21:56

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks reds for taking the time to answer me. Pls see my comment above. Will crawl back under my stone now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.