0

I am looking for an alternative to SQL Server Agent jobs - there is a need to control running and scheduling of processes (executables, "jobs") and so I intend to implement a Windows Service that will act as a scheduler for these processes.

These processes are not interactive, so there is no problem starting them from a Windows Service, but they need to work with SQL Server - reading and writing data, executing stored procedures etc.

Commands to windows service ("scheduler") - like "enqueue a job" - would be passed from SQL Server CLR in UDF or directly from a client side web app via WCF (haven't decided yet).

Is this a right way to do this? Are there any access and security issues should I be aware of? I am particulary worried about possible limitations on processes run from a windows service.

Please share your experiences with similar designs.

Also, I consider using SQL Server Service Broker (suggested in similar thread) but I am not sure if it fits my needs.

Thank you! Adam

4

1 回答 1

1

达到合理安全级别的正确方法是:

  • 创建一个将运行 Windows 服务的新用户(您可以在控制面板中创建此用户)
  • 在 SQL Server 中为该用户创建一个新登录名(使用集成安全性)
  • 在 SQL Server 中为该用户提供必要但最低限度的权限

要实现服务,您必须了解以下几点:

  • 如果您使用 WCF(或任何其他服务堆栈),则需要一个线程来侦听请求,并需要一个不同的线程来运行 SQL Server 中的进程。如果没有,后续请求可能会超时。(您可以为每个任务启动新线程,或实施队列以避免服务器过载)。
  • 处理错误(异常)时要格外小心。如果抛出未处理的异常,您的服务将停止,直到有人再次启动它
  • 实现 UDF 解决方案更难,因为您需要修改 SQL Server 安全设置以允许 UDF 与“外部世界”通信
  • 您应该在您的服务中包含某种登录,以便您可以测试它并验证它是否正常工作。

制作可以作为控制台应用程序和服务运行的可执行文件并不难。如果这样做,您可以从 Visual Studio 调试器运行它,或者单独运行它,然后登录控制台 ( Console.Write...(...)),看看发生了什么。

于 2014-01-15T11:51:40.873 回答