-2

This is the connection string that connect the C++ code with the MySQL and this is hardcoded so if some other user have to run the solution they have to change the username servername Pwd. My question is how do I remove this hard code so that it will be efficient and everyone can run the solution without having change anything?

ost <<" DRIVER=SQL Server Native Client 11.0; SERVER=Avchar-D\\ENTERPRISE2014;Database="<< czDataSourceName << ";Uid=da; Pwd=P@ssw0rd10;Integrated Security=SSPI;Persist Security Info=False";
Dale K
  • 25,246
  • 15
  • 42
  • 71
  • 2
    Why are you showing us your password? And what is the question? – PaulMcKenzie Nov 19 '19 at 17:13
  • This is not the correct password so don't worry about the password. So my question is " this is the connection string that connect the C++ code with the MYSQL and this is hardcoded so if some other user have to run the solution they have to change the username servername Pwd. My question is how do I remove this hard code so that it will be efficient and everyone can run the solution without having change anything. – Sumit Koirala Nov 19 '19 at 17:20
  • 1
    You create string variables and read into them by whatever means, and then use those instead of hard-coded strings? Seriously, your question is so broad, that's the only response that would make sense. – PaulMcKenzie Nov 19 '19 at 17:22
  • 1
    store it in a configuration file somewhere or if you are on windows you could use the registry – Alan Birtles Nov 19 '19 at 17:24
  • This has nothing to do with SQL. It's just asking how to take configuration into your app at runtime. Covered in a bazillion places online and probably in your book! – Lightness Races in Orbit Nov 19 '19 at 18:34
  • Alan, I am using the boost library 1_58 so I am not sure what need to be stored in the configuration file?? Can you help me with making the configuration file?? – Sumit Koirala Nov 19 '19 at 20:51
  • Read connection string from environment. – basit raza May 07 '20 at 21:25

1 Answers1

0

Try this:

const char mysql_string[] =
" DRIVER=SQL Server Native Client 11.0; SERVER=Avchar-D\\ENTERPRISE2014;Database=";
ost << mysql_string;

By assigning the connection string to a variable and sending the variable's content to the server, you have set up for non-hard coded text. You can set mysql_string to anything you want (including input from User), as long as the assignment is before the statement that sends to the server.

Edit 1: Passwords
You may want to hard code the account or password to a development account. This way the password doesn't need to change; the code logs into a development account which developers have access to.

You could do something like:

#if NDEBUG
// Assign to production account
#else
// Assign to development server/account.
#endif
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154