C# 中的常规数据库作业的计划任务或服务?
我有一个 Web 服务器和一个数据库服务器,我想运行一个使用现有 C# DLL 来访问数据库并执行一些计算的作业。
用 C# 创建控制台应用程序并将其安排在 Web 服务器(应用程序服务器)上以针对数据库服务器运行是最简单的方法吗?
我认为 SSIS 是一个选项,但我不太了解,所以我认为将控制台应用程序安排为任务是最好的。
你怎么认为?
I've got a web server and a database server, and I'd like to run a job that uses an existing C# DLL to access the database and perform some calculations.
Is the simplest method to create a console app in C# and schedule it on the web server (app server) to run against the DB server?
I see SSIS as an option, but I don't know that well, so I thought a console app scheduled as a task would be best.
What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我非常喜欢控制台应用程序+计划任务方法。 它往往更干净、更容易测试,并且在出现问题时更容易重新运行。 也就是说,如果您可以用纯 SQL 编写计算,则可以将所有内容作为 SQL 作业运行。 或者,您可以利用 SQLCLR(位于 SQL Server 中的 .NET 程序集,基本上显示为存储过程或 UDF),并完全在 SQL 作业引擎中运行。
I'm a big fan of the console app + scheduled task approach. It tends to be cleaner, easier to test, and easier to re-run if something goes south. That said, if you can write the calculations in pure SQL, you could just run everything as a SQL job. Alternatively, you could take advantage of SQLCLR (.NET assemblies living within SQL Server and basically appearing as a sproc or UDF) and also run things entirely within the SQL job engine.
如果工作量很小,则无需为此编写单独的控制台应用程序。 您可以单独编写一个页面并编写一个批处理文件(即调度程序)来调度它。 您还可以通过窗口的用户界面来安排它。 除此之外,如果您的工作是维护计划的计划/步骤(例如重新索引、备份数据库、碎片整理、清理历史记录/日志等),那么从您的 sql server 中的“管理”下为其创建一个维护计划” 文件夹可用。
You don't need to write a separate console application for that if the job is very minor. you can write a page separately and write a batch file i.e. a scheduler fr the same to schedule it. You can also schedule it through window's user interface. Apart for that, if your job is plan/step of a maintenance plan (like re-indexing, taking backup of db, defragmenting , cleaning up history/log etc) then create a maintenance plan for it from you sql server, under "Management" folder available.
您还可以从 PowerShell 脚本调用 C# DLL,并将该脚本作为计划任务执行。
对于需要在后台立即执行操作的操作,我更喜欢为每个项目提供一项服务。
You can also call your C# DLL from a PowerShell script, and execute that script as a Scheduled Task.
For operations that require immediate actions in the background I prefer to have a service for each of my projects.
是的,最简单的解决方案是创建一个单独的控制台应用程序并将其作为计划任务运行。
您已经可以访问网络服务器,并且所有工具都已经就位,无需安装其他任何东西。
Yes the simplest solution is to create a separate console app and run it as a scheduled task.
You've got access to the web server and all the tools are already in place without having to install anything else.
您可以使用 Quartz.NET 库 (quartznet.sourceforge.net) 在控制台应用程序中进行调度,它是开源的,并且运行完美!
You can use Quartz.NET library (quartznet.sourceforge.net) for scheduling within your console app, it is open source and it works perfectly!