1

I have created a Windows Forms Application on Visual Studio using C#. This application connects to a mysql server which has the database. The connection to the server is currently being done with this line of code:

    string connStr = @"server=192.168.1.5;userid=vangelis;password=121298;database=mydatabase";

However I am intending to sell the application to multiple customers. I am assuming that on the computer of each customer I will have to install mysql workbench and create the database. However the rest of the computers in their office will connect to the computer with the mysql workbench. However the problem is the

server=192.168.1.5

Their computers will most definetely have different ip's. How can I fix this problem without changing this line of code for each customer?

  • 2
    Does using App.config file help? – dcansyn Oct 17 '20 at 23:05
  • @dcansyn what do you mean by that? –  Oct 17 '20 at 23:06
  • You can change the settings file instead of constantly updating the application. https://stackoverflow.com/questions/6536715/get-connection-string-from-app-config – dcansyn Oct 17 '20 at 23:07
  • @dcansyn if I configure the app.config file to get the computer's ip, it won't work, because we only need the "host" computer ip which will have the mysql server on it. Have I misunderstood something? –  Oct 17 '20 at 23:11
  • @Maverick98 The IP would be manually configured (or automated with database creation/deployment, if that's an installer process) into the `App.config` at the time of installation. It would be the IP of the machine hosting the database. The advantage of the `App.config` vs hard-coding the IP in code is that you don't need to recompile the code for each customer. Ultimately, it's more than just the IP - it's a full connection string, possibly with credentials of the db user, which might also differ from customer to customer. – CoolBots Oct 17 '20 at 23:13
  • @CoolBots oh ok I get it know, thank you! –  Oct 17 '20 at 23:14

0 Answers0