在VB.Net中使用MS SQL DB创建Windows服务 [英] Creating a Windows Service with MS SQL DB in VB.Net

查看:69
本文介绍了在VB.Net中使用MS SQL DB创建Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是一名中级程序员。我迫切需要有关如何创建Windows服务的帮助。我已经阅读了几篇有关服务的文章,但似乎没有任何关于数据库连接的解释,所以只是在这里发布这个问题,所以你们中的任何一个大师都可以提供帮助。



我在服务器位置有几个文件。该服务将连接到数据库并检查是否已经处理了已指定的文件,如果是,那么它将不会被处理。否则,将通过将文件移动到新位置并将文件名和处理日期插入到MS SQL Server DB上的表中来处理该文件。



请注意我的数据库连接是通过配置文件进行的。



其实我有一个工作程序,每次用户点击表单上的按钮进行处理时(Windows表格程序已存在)。我只是想消除这一点,并自动进行Windows服务处理。



请帮助我如何创建Windows服务。



提前感谢你。

Hello, I'm an intermediate programmer. I just desperately need assistance as to how to create a Windows Service. I have read several articles on services but none of them seem to explain anything on DB connection as well so just posting this question here so any of you gurus can assist.

I have several files on a sever location. The service will connect to the DB and check if the spcified file has been processed already or not, it if is then it will not be processed. Otherwise the file will be processed by moving it to a new location and inserting the file names and the date processed into a table on the MS SQL Server DB.

Note that my DB connection is doen via a config file.

Actually I have a working program where every time a user is clicking a button on a form to do the processing (Windows Form program is in existence). I just want to eliminate this and have the Windows Service process it automatically.

Please assist with this as to how I can create the windows service.

Thanking you in advance.

推荐答案

希望这会有所帮助。



在Visual Studio中,您有一个项目可以自动为您创建一个Windows服务项目。



在创建此项目时,您将在项目中获得一个类name service1。



这里有OnStart和OnStop等方法。



你做的是创建一个线程或计时器,通过单击按钮继续重复当前正在进行的过程。



如果是线程,则需要创建一个循环重复这个过程,但是不要忘记在每次循环后在线程中使用Sleep函数。



如果是计时器,它会在指定的间隔后自动调用。



在OnStart事件中初始化并启动线程或计时器。



将最后一行放入OnStart作为Application.Run的事件,为了保持服务运行,否则它将停止,如果它无关。
Hope this helps.

In Visual Studio you have a project that automatically creates a Windows Service Project for you.

On Creating this, you will get a class in the project with the name service1.

In this there will be methods like OnStart and OnStop.

What you do is create a thread or a timer to keep repeating the process the you are currently doing by clicking a button.

In case of thread, you will need to create a loop for repeating the process, but do not forget to use Sleep function in thread after each loop.

In case of timer it will be automatically called after specified interval.

Initialize and start the thread or timer in OnStart event.

Put the last line in OnStart event as Application.Run, to keep the service running, else it will stop if it has nothing to do.


这篇关于在VB.Net中使用MS SQL DB创建Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆