tags:

views:

56

answers:

2

I am using the below string in my code :

string AAR_FilePath = "\"C:\\MySQL\\MySQL Server 5.0\\bin\\mysqldump\"";

which i dont want to hardcore in my code. So i need to use that in my app.config I tried to give the same value as,

<add key="Path_SqlDump" value="\"C:\\MySQL\\MySQL Server 5.0\\bin\\mysqldump\""></add>

But the above gives me error, because of the quotes.

All i need is, i should be able to assign "\"C:\MySQL\MySQL Server 5.0\bin\mysqldump\""

to a string. HOW ?

public string AAR_FilePath = ConfigurationSettings.AppSettings["Path_SqlDump"].ToString();     

public void CreateScript_AAR()
{
    //AAR_FilePath = "\"C:\\MySQL\\MySQL Server 5.0\\bin\\mysqldump\"";
    string commandLine = @"" + AAR_FilePath + " -u" + DbUid + " -p" + DbPwd + " " + DbName + " > " + Path_Backup + FileName_Backup;  
    System.Diagnostics.ProcessStartInfo PSI = new System.Diagnostics.ProcessStartInfo("cmd.exe");
    PSI.RedirectStandardInput = true;
    PSI.RedirectStandardOutput = true;
    PSI.RedirectStandardError = true;
    PSI.UseShellExecute = false;
    System.Diagnostics.Process p = System.Diagnostics.Process.Start(PSI);
    System.IO.StreamWriter SW = p.StandardInput;
    System.IO.StreamReader SR = p.StandardOutput;
    SW.WriteLine(commandLine);
    SW.Close();
}
+6  A: 

You don't do all that escaping in the app.config. That is a C# thing. Just put the full path in the app.config as you would in a command prompt.

<add key="Path_SqlDump" value="C:\MySQL\MySQL Server 5.0\bin\mysqldump\" />
John
@John, i tried that already, i'm not getting my result. But if i pass the value like..string AAR_FilePath = "\"C:\\MySQL\\MySQL Server 5.0\\bin\\mysqldump\"";It works fine if u hardcore !!!
Anuya
What I've shown here is correct. If it is not working then you will need to update your question with the code you are using to access this key and be specific about what is not working.
John
+1  A: 

John's answer is correct, you just have to do this in your C# code(the MySQL Server 5.0 has spaces in them):

 string commandLine = "\"" + AAR_FilePath + "\"" + " -u" 
        + DbUid + " -p" + DbPwd + " " + DbName + " > " 
        + "\"" + Path.Combine(Path_Backup,FileName_Backup) + "\"";

So your command will look like this:

"C:\MySQL\MySQL Server 5.0\bin\mysqldump" -u -sampUid -p sampPassword yourDbName > "c:\archive\2010-05-12.backup"

Just strip the last backslash, mysqldump is mysqldump.exe? right?

<add key="Path_SqlDump" value="C:\MySQL\MySQL Server 5.0\bin\mysqldump" />
Michael Buen