使用Visual C#的bcp实用程序

时间:2015-03-26 10:41:45

标签: c# bcp

我尝试在Visual C#中使用SQL Server bcp实用程序,如下所示:

command = new SqlCommand ("bcp "+ onlineConnect.Database+".dbo.T1 out "+ ConfigurationManager.AppSettings ["caleonline"]+"T1.dat -n -S " + onlineConnect.DataSource+" -U sa -P a" ,onlineConnect ); 

当我使用断点运行时,我得到了这个:

CommandText 
"bcp ONLINE.dbo.T1 out H:\\ONLINE\\fisiere\\T1.dat -n -S ATTY\\SQLEXPRESS -U sa -P a"   

但是我收到了错误:

  

System.Data.SqlClient.SqlException未处理Message =语法不正确附近'。'。

1 个答案:

答案 0 :(得分:1)

使用exec xp_cmdShell

添加命令前缀
command=new SqlCommand ("exec xp_cmdShell 'bcp.exe'"+ onlineConnect.Database+".dbo.T1 out "+ ConfigurationManager.AppSettings ["caleonline"]+"T1.dat -n -S " + onlineConnect.DataSource+" -U sa -P a" ,onlineConnect );