[英]Cancel executing query in SQL via C#
I know how to cancel a SQL Command in C# (command.Cancel()) but now I have the following code executing a SQL script which takes a longer time. 我知道如何取消C#中的SQL命令(command.Cancel()),但是现在我有以下代码执行需要较长时间的SQL脚本。 I want that the user can cancel this process but don't know how to do this. 我希望用户可以取消此过程,但不知道如何执行此操作。
string file = File.ReadAllText(workingDir + @"\" + fileName);
// execute
SqlConnection conn = new SqlConnection(conString);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(file);
Is there a method or something to stop that? 有什么方法或方法可以阻止这种情况吗? I haven't found one yet and Cancel does not work. 我还没有找到,并且取消不起作用。 Thanks in advance! 提前致谢!
如果您要杀死进程,就像用户从SSMS杀死进程一样,请使用以下内容。
server.KillProcess(server.ConnectionContext.ProcessID);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.