The order of your parameter is incorrect, it must be:
db_server, db_Name, db_User, db_Pass
Currently it is:
"server = {0}; database = {1}; uid = {2}; pwd = {3}" db_Server db_User db_Pass db_Name
So your statement should be:
MySqlConnection myConnection = new MySqlConnection(string.Format( "server = {0}; database = {1}; uid = {2}; pwd = {3}", db_Server,db_Name, db_User, db_Pass));
EDIT: Based on the comments and discussion, the error you get is that you are trying to use all the materials at the class level. You should have these lines inside the method and call this method where you need it. Sort of:
class MyClass { string db_Server = "10.0.0.0"; string db_User = "myUser"; string db_Pass = "myPassword"; string db_Name = "myDatabase"; public MySqlConnection GetConnection() { MySqlConnection myConnection = new MySqlConnection(string.Format( "server = {0}; database = {1}; uid = {2}; pwd = {3}", db_Server, db_Name, db_User, db_Pass)); return myConnection; } }
source share