Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 执行bcp以插入数据库_C#_Sql Server_Bcp - Fatal编程技术网

C# 执行bcp以插入数据库

C# 执行bcp以插入数据库,c#,sql-server,bcp,C#,Sql Server,Bcp,我已经编写了一个C#程序来执行bcp命令,并将.txt文件中的数据传输到SQL Server表中。当我使用命令行执行命令时,它执行得很好 当我运行如下所示的程序时,会出现以下错误: 在System.Diagnostics.Process.get_StandardError() 在…标准错误尚未重定向 代码: 加: 如果您想访问代码后面的p.StandardError,则需要此选项。我已编辑了您的标题。请看“”,其中的共识是“不,他们不应该”。谢谢!!这就解决了错误。现在,我的程序运行了大约30秒

我已经编写了一个C#程序来执行
bcp
命令,并将
.txt
文件中的数据传输到SQL Server表中。当我使用命令行执行命令时,它执行得很好

当我运行如下所示的程序时,会出现以下错误:

在System.Diagnostics.Process.get_StandardError()
在…标准错误尚未重定向

代码:

加:


如果您想访问代码后面的
p.StandardError
,则需要此选项。

我已编辑了您的标题。请看“”,其中的共识是“不,他们不应该”。谢谢!!这就解决了错误。现在,我的程序运行了大约30秒,但没有向表中写入任何内容。我如何调试这个??
string outputfilename = @"C:\Output.txt";
string cmdExe = "MyDB.dbo.a in outputfilename -c -T -S servername\\DEV -U readonly -P readonly -F2";
 System.Diagnostics.Process p = new System.Diagnostics.Process();
 p.StartInfo.WorkingDirectory = @"C:\\";
 p.StartInfo.UseShellExecute = false;
 p.StartInfo.RedirectStandardOutput = true;
 p.StartInfo.CreateNoWindow = true;
 p.StartInfo.FileName = "BCP";


 p.StartInfo.Arguments = cmdExe;

 try
 {
     p.Start();
     p.BeginOutputReadLine();

     StreamReader myStreamReader = p.StandardError;
     // Read the standard error of net.exe and write it on to console.
    Console.WriteLine(myStreamReader.ReadLine());
 }
 catch (Exception e)
 {
     Console.WriteLine(e.StackTrace.ToString());
     Console.WriteLine(e.Message);
     Console.ReadLine();
 }
 if (p.WaitForExit(100))
 {
     // Process completed. Check process.ExitCode here.
     p.StandardOutput.ReadToEnd();
 }
p.StartInfo.RedirectStandardError = true;