我尝试在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 =语法不正确附近'。'。
答案 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 );