0

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 ?

4
  • 2
    you are hardcoding the host in the connection string. Commented May 7, 2014 at 18:23
  • 1
    You are pointing to localhost for your MySQL server... is this installed on the target system? Commented May 7, 2014 at 18:24
  • Yes this my MYSQL server name that installed in my laptop Commented May 7, 2014 at 18:26
  • 1
    @user3525082, but the target machine doesn't have an instance installed at all or one with that name. Commented May 7, 2014 at 18:27

1 Answer 1

2
  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;
Sign up to request clarification or add additional context in comments.

2 Comments

This is what i founded in App. config ( <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> </configuration> )
@user3525082, so add the sections that are appropriate based off of the MSDN article I linked to.

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.