In the app.config file, I have:
add key="DataFileLocation" value="E:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\"/>
In the code I have:
Process P2 = new Process();
P2.StartInfo.FileName = "restore.bat";
P2.StartInfo.Arguments = + "\"" + DataFileLocation.ToString() + "\"";
P2.StartInfo.UseShellExecute = false;
P2.StartInfo.RedirectStandardOutput = true;
P2.StartInfo.CreateNoWindow = true;
P2.Start();
The output to 'restore.bat' is:
-v dataloc=\"E:\\Program Files\\Microsoft SQL Server\\MSSQL12.MSSQLSERVER\\MSSQL\\DATA\\\"
As you can see, there's an extra "\\" at the beginning which is breaking the bat/sql statement...
Andrew
In your case it seems like you are already adding a extra \\
, so is the output according to your logic.
The best way to combine path is that you should use the Path.Combine
method provided by static Path
class, it takes care of all the extra \\
Try this
var finalPath = Path.Combine(DataFileLocation.ToString(), "what_ever_path_you_want_to_combine");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.