0

I developed a C#/WPF application utilizing Entity Framework 6 to connect to a local MySQL database. The application works perfectly when running on the local computer. However, when I install the application on other systems and run it, it crashes the moment it needs to access the database.

Catching the exception and making a message pop-up, I get the message "Value cannot be null. Parameter name : source." From this post, Value cannot be null. Parameter name: source, I presume that it is because my connection string is wrong or I am not doing something correctly to allow remote database access.

This is my connection string in App.config: connectionString="metadata=res://*/Database.csdl|res://*/Database.ssdl|res://*/Database.msl;provider=MySql.Data.MySqlClient;provider connection string="server=(ipAddress);user id=root;password=password;persistsecurityinfo=True;database=practice""

The ip address I am using is the real ip address of the local system obtained from cmd => ipconfig => IPv4.

After a lot of googling and searching through stack overflow, I have not yet found a solution to this. I do not want a local instance of the database on the other computers, they should all remotely connect to the database hosted on the local computer. I do not think there should be any issue connecting because all the systems are on the same network and I can ping the computer with the local database from the other computers.

I have tried giving remote access to the other computers in MySQL using the following statements: CREATE USER '%'@'(IPADDRESS)' IDENTIFIED BY ''; GRANT ALL PRIVILEGES ON *.* TO '%'@'(IPADDRESS)' WITH GRANT OPTION; Also tried following Asaf's solution in this post (WPF application doesn't work in other computers). However, neither worked for me.

If anyone can explain how to publish a C#/WPF application with access to MySQL database, that would be great.

EDIT: After editing the code more to see the exception, I am getting the error "The underlying provider failed on Open." Looking into that now.

EDIT: SOLVED! Thank you to obl. Needed to enable remote connection as 'root' (How to allow remote connection to mysql), flush privileges, and restart MySQL Server. Afterwards, the application worked.

Jonathan Tan
  • 129
  • 2
  • 3
  • 12
  • 1
    Enable remote connection as 'root': https://stackoverflow.com/questions/14779104/how-to-allow-remote-connection-to-mysql – obl Jul 21 '17 at 22:04
  • Unfortunately, that did not do it. After editing the code a bit more though to see where the exception is coming from, I am getting the error "The underlying provider failed on Open." Looking into this now. – Jonathan Tan Jul 21 '17 at 22:11
  • Did you check if the connection port is opened on the database server (firewall settings) ? The default port is 3306 for mysql ... – hugo Jul 21 '17 at 22:19
  • Just kidding Obl! Your solution fixed it, just needed to flush privileges and restart MySQL server again (don't know why, but needed to restart it twice before the remote root access took effect). Thank you so much! – Jonathan Tan Jul 21 '17 at 22:19
  • While trying to solve this problem, I did need to add the connection port to the firewall and also added it to my connection string just in case. I do not think this solved my posted problem but probably saved me from future troubles. – Jonathan Tan Jul 21 '17 at 22:24

1 Answers1

0

Thanks to Obl, I solved the problem by enabling remote connection as 'root' (How to allow remote connection to mysql). Afterwards, just had to flush privileges and restart MySQL server.

Jonathan Tan
  • 129
  • 2
  • 3
  • 12