[英]using bcp to export data to text fie with c#
this is my .bat file it works in command prompt but in my c# code it dose not work: this the .bat file code: 这是我的.bat文件,它可以在命令提示符下工作,但是在我的C#代码中,它不能工作:这是.bat文件代码:
bcp "select * from %4.att.Attendance where Date <= '%5' " queryout "Attendance.txt" -c -b 200000 -S %1 -U %2 -P %3
bcp "select * from %4.att.PairedAttendnce where Date <= '%5' " queryout "PairedAttendnce.txt" -c -b 200000 -S %1 -U %2 -P %3
bcp "select * from %4.att.PersonDateStructure where Date <= '%5' " queryout "PersonDateStructure.txt" -c -b 200000 -S %1 -U %2 -P %3
bcp "select * from %4.att.dailyResult where Date <= '%5' " queryout "DailyResult.txt" -c -b 200000 -S %1 -U %2 -P %3
bcp "select * from %4.att.WPResult where WPID <= %7 " queryout "WPResult.txt " -c -b 200000 -S %1 -U %2 -P %3
bcp "select * from %4.att.BaseResultCredit where date <= '%5'" queryout "BaseResultCredit.txt" -c -b 200000 -S %1 -U %2 -P %3
bcp "select * from %4.att.Credit where StartDate <= '%5' " queryout "Credit.txt" -c -b 200000 -S %1 -U %2 -P %3
bcp "select * from %4.Wfo.nwfDoc where SDate <= '%5'" queryout "nwfDoc.txt" -c -b 200000 -S %1 -U %2 -P %3
bcp "select * from %4.Sec.Eventlog where REPLACE(LEFT(CONVERT(VARCHAR, CreateDateTime, 120), 10), '-', '/') <= '%6' " queryout "Eventlog.txt" -c -b 200000 -S %1 -U %2 -P %3
bcp "select * from %4.Cms.DDLLog where REPLACE(LEFT(CONVERT(VARCHAR, PostTime, 120), 10), '-', '/') <= '%6' " queryout "DDLLog.txt" -c -b 200000 -S %1 -U %2 -P %3
and this is the c# code : 这是C#代码:
string MyBatchFile = System.IO.Directory.GetCurrentDirectory() + @"\BatchFiles\Export.bat";
var process = new System.Diagnostics.Process();
DateTime dt = PersianDate.ConvertDate.ToEn (dateOfArchive);
process.StartInfo.FileName = MyBatchFile;
// process.StartInfo.Arguments = String.Format("\"{0}\"", serverDBIP, ServerDbUserName, ServerDbPassword, ServerDBName, dateOfArchive, dt.ToShortDateString(), wpid);
process.StartInfo.Arguments = String.Format("\"{0}\"\"{1}\"\"{2}\"\"{3}\"\"{4}\"\"{5}\"\"{6}\"",
serverDBIP, ServerDbUserName, ServerDbPassword, ServerDBName, dateOfArchive,dt.ToShortDateString(), wpid);
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
bool b = process.Start();
Thread.Sleep(20000);
//string errorMessage = process.StandardError.ReadToEnd();
process.WaitForExit();
//string outputMessage = process.StandardOutput.ReadToEnd();
//process.WaitForExit();
process.Close();
return b;
does any body know why the code does not work? 有谁知道为什么代码不起作用?
It is most likely that your file is created under process.StartInfo.WorkingDirectory
(which is default right now) 您的文件很可能是在process.StartInfo.WorkingDirectory
下创建的(目前是默认设置)
You need to set 你需要设置
process.StartInfo.WorkingDirectory = <your-working-dir>
in order to be able to save your batch results in a given directory. 为了能够将批处理结果保存到给定目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.