tariq
tariq

Reputation: 43

Create setup file include MySQL database inside it

I developed application form using C# and connected this application with a MySQL database like this

string Coonstring = "datasource=localhost;port=3306;username=root;password=***;Charset=utf8";
string cmd = "select name from project.material ;";
MySqlConnection connectionDatabase = new MySqlConnection(Coonstring);
MySqlCommand cmddata = new MySqlCommand(cmd, connectionDatabase);
MySqlDataReader myreader;

When I try to build this app. and create setup file and get this setup file to another laptop error messagbox appear tell me missing MySQL host.

enter image description here

So what should I do ?

Upvotes: 0

Views: 1204

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67928

  1. Add an application configuration file. MSDN Link
  2. Add an entry for a connection string - this can now be changed when deployed. MSDN Link
  3. Change your code to use it (as shown below).
  4. Set the connection string appropriately on the deployed system in the *.exe.config file.

string Coonstring = ConfigurationManager
    .ConnectionStrings["KeyValueYouSupplied"]
    .ConnectionString;

Upvotes: 2

Related Questions