如何调用存储过程而不等待它完成?

发布于 2024-08-16 10:40:01 字数 293 浏览 6 评论 0原文

如何从 Web 服务方法调用存储过程,而不必等待存储过程完成,而只需让该方法完成所有其他活动?

举个例子(不是实际情况,但更容易理解): 我有一个有 1000 万行的表格房屋,每年我都必须根据土壤、建筑等计算每栋房屋的价值。

在年底之前,我输入新的土壤和建筑参数,然后让数据库计算每栋房子的价值(使用从 Web 服务方法调用的存储过程),但这可能需要几个小时。用同样的方法,我希望能够告诉系统我已经开始计算(在开始之后,而不是之前)。

那么在这里我如何避免超时,并让我的网络应用程序继续做其他事情。

谢谢。

How do I call a stored procedure from a web service method without having to wait for the stored procedure to finish, and just let the method finish all other activities?

As an example (not actual situation but much simpler to understand):
I have a table houses with 10 million rows, and each year I have to calculate what each house is worth based on soil, constructions, etc.

Before the year ends, I feed new parameters of soil and constructions, and then let the database calculate each house's worth (with a stored procedure called from a web service method), but it may take hours. In this same method, I want to be able to tell the system that I have started calculating (after it starts, not before).

So here How would I avoid a time out, and let my web app to continue doing other things.

thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

苍景流年 2024-08-23 10:40:01

如果您不依赖于存储过程的结果,则可以将存储过程调用包装在方法中并使用

        Thread statisticsThread = new Thread(new ThreadStart(YourSPWrapper));
        statisticsThread.Priority = ThreadPriority.Lowest;
        statisticsThread.Start();

If you do not depend on the results of the stored procedure, you can wrap your stored procedure call inside a method and call it using

        Thread statisticsThread = new Thread(new ThreadStart(YourSPWrapper));
        statisticsThread.Priority = ThreadPriority.Lowest;
        statisticsThread.Start();
独留℉清风醉 2024-08-23 10:40:01

您是在谈论调用一个不返回任何内容的 SP 吗?就像在服务器上开始工作一样?

您可以尝试使用异步委托来执行此操作,线程池可能是最简单的:

ThreadPool.QueueUserWorkItem(myDelegateFunction);

protected void myDelegateFunction(object state) {
   //make your db call here and let the delegate fall out of scope
   //if you need to set a variable saying it succeeded, set a global here
}

然后您可以在需要时启动委托,当有可用线程资源时,它将在异步委托中执行。

Are you talking about calling a SP which returns nothing? Like kicking off a job on the server?

You could try using an asyncronous delegate to do it, threadpool is probably the easiest:

ThreadPool.QueueUserWorkItem(myDelegateFunction);

protected void myDelegateFunction(object state) {
   //make your db call here and let the delegate fall out of scope
   //if you need to set a variable saying it succeeded, set a global here
}

You can then kick off the delegate whenever you want it to be done, and it will be executed in a asynchronous delegate when there are thread resources available.

花海 2024-08-23 10:40:01

也许考虑使用 SQL Server 代理将查询安排为作业?
如果作业需要定期运行或很少运行,则这是特别值得的。

如果绝对必要,您还可以使用 SQL 脚本根据 Web 应用程序的需要安排作业。只需确保代理服务正在运行,否则您的作业将无法启动。

Perhaps consider using SQL Server Agent to schedule the query as job?
This is especially worthwhile if the job needs to run on a regular schedule or only very rarely.

If absolutely necessary, you can also use use a SQL script to schedule the job on demand from your webapp. Just ensure the agent service is running, otherwise your job won't start.

紫南 2024-08-23 10:40:01

使用 IBM Informix Dynamic Server 11,您可以考虑通过 DB-Cron 任务调度程序运行该过程。该程序将作为同步数据库请求启动该操作,但该任务不需要在请求完成之前完成。

With IBM Informix Dynamic Server 11, you could consider running the procedure via the DB-Cron task scheduler. The program would initiate the operation as a synchronous database request, but the task would not need to complete before the request was complete.

白芷 2024-08-23 10:40:01

我发现的另一个解决方案涉及 sql server 代理,这对于一个简单的问题可能有点过分,但它可以非常方便

http://msdn.microsoft.com/en-us/library/ms345108(v=sql.90).aspx#sqlsvcbr_topic6
http://blog.sqlauthority.com/2009/09/21/sql-server-intorduction-to-service-broker-and-sample-script/

Another solution I found involves the sql server broker which might be overkill for a simple problem, but it can come in very handy

http://msdn.microsoft.com/en-us/library/ms345108(v=sql.90).aspx#sqlsvcbr_topic6
http://blog.sqlauthority.com/2009/09/21/sql-server-intorduction-to-service-broker-and-sample-script/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文