执行master.xp_cmdshell BCP 选择



下面,我从c#.net windows窗体调用一个存储过程。

存储过程包含以下内容:

 exec master..xp_cmdshell ''bcp "select ''''Column1'''',''''Column2'''',''''Column3'''',''''Column4'''',''''Column4'''',''''Column5'''',''''Column6'''',''''Column7'''',''''Column8''''" queryout "' + @Parent_Folder + @Transformed_Tbl + '.csv" -c -t, -T -Slocalhost'''
    exec master..xp_cmdshell ''bcp Databasename..' + @database table+ ' out "' + @serverfolder+ 'temp_' + @user specified file name + '.csv" -c -t, -T -Slocalhost'''
    exec master..xp_cmdshell ''copy /b "' + @serverfolder+ @user specified file name + '.csv" + "' + @serverfolder+ 'temp_' + @user specified file name + '.csv" "' + @serverfolder + @user specified file name+ '.csv"'''

它运行完美,

但有时用户希望取消此过程。当用户点击取消按钮时,如何取消此正在运行的 bcp 进程。这是我在本地系统中的应用程序,我正在从另一个sql服务器系统访问数据库,然后将文件保存在同一个sql服务器系统中。

请给我一个关于这个问题的想法。

使用"xp_cmdshell"并不安全,因为它允许您执行所有这些操作系统级别的事情,例如运行外部 executable.it 建议不要使用"xp_cmdshell"。

您应该寻找xp_cmdshell的替代品-

http://www.mssqltips.com/sqlservertip/2014/replace-xpcmdshell-command-line-use-with-sql-server-agent/

无法使用

T-SQL 命令从 SQL Server 取消xp_cmdshell。您必须删除"取消"并从应用程序中导出的功能,因为实际上是不可能的。如果要进行可取消的导出,则必须使用 xp_cmdshell 滚动自己的 w/o。

有些人可能会建议杀死生成的 bcp 进程,但这存在许多问题的缺陷(发现正确的进程是最简单的进程),并且毫不客气地杀死进程可能会产生可预测的结果,例如在上游使用工作流中馈送的部分完成的损坏导出文件。

最新更新