服务启动,但应用程序无法运行 [英] Service starts but application does not run

查看:103
本文介绍了服务启动,但应用程序无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用非常简单的OnStart代码创建了一个服务.  应该调用一个应用程序,该应用程序扫描SQL数据库表,从该表中提取数据,通过WCF调用发送数据,并通过状态更改来更新另一个表.

I have created a service with very simple OnStart Code.  It is supposed to invoke an application that scans an SQL database table, extract data from that table, send the data with WCF calls, and update another table with a status change.

我的应用程序可以作为控制台应用程序或WinForm正常运行.  所有代码都是使用Visual Studio Professional 2012 Update 5用Visual Basic编写的. 所有代码都是在发布模式下编译的.

My application runs ok either as a console application or as a WinForm.  All code is written in Visual Basic using Visual Studio professional 2012 Update 5.  All code is compiled in Release mode.

我确定该服务实际上正在调用我的应用程序,因为它引用了其他dll.  如果缺少任何内容,则会在事件日志中生成找不到文件"错误.  但是,未扫描数据表并且未更新状态 正在执行.  应该在调用它时将开始日期/时间写入数据库表之一中的列.

I am sure that the service is actually calling my application because it references other dlls.  If any are missing, a file not found error is generated in the event log.  However, the data table is not being scanned and the status update is not being performed.  It is supposed to write the start date/time to a column in one of the database tables when it is invoked.

如果通过Windows资源管理器调用了我的应用程序,则该服务是否正在运行.

My application runs correctly if it is invoked through Windows explorer, whether or not the service is running.

OnStart代码如下.  服务项目的参考资料包括对我的SW应用程序的参考资料.  该应用程序及其dll位于bin \ release目录中.

The OnStart code is as follows.  The references for the service project include a reference to my SW application.  That application and its dlls are located in the bin\release directory.

   受保护的重写Sub OnStart(ByVal args()作为字符串)
        '在此处插入代码以定义处理.
       昏暗的SW作为新的SW.SW
        SW.Show() (我也尝试对此进行评论)
        SW.Activate()
   结束

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Insert code here to define processing.
        Dim SW As New SW.SW
        SW.Show() (I have attempted commenting this out also)
        SW.Activate()
    End Sub

我还尝试过更改服务以与桌面交互.  这需要通过注册表启用桌面交互.  但是服务会在开始"时挂断模式出现错误1053,如果没有系统就无法停止 重新启动.

I have also tried changing the service to interact with the desktop.  That required enabling desktop interaction through the registry.  But then the Service hangs up in "Starting" mode with error 1053 and cannot be stopped without a system Restart.



推荐答案



对服务进行故障排除非常复杂.我建议您为该服务创建单独的日志文件,以便可以查看该服务已完成的工作.一个用于执行操作的日志文件,另一个用于记录错误的文件.  

您确定该服务能够连接到数据库吗?您可以尝试一个简单的测试以连接到表并将行数写入日志文件.

Hi,

It's quite complicated to troubleshoot services. I would recommend you to create separate log files for the service so you can see what the service has been done. One logfile for the actions that are performed and another file that logs the errors.  

Are you sure that the service are able to connect to the DB? You could try a simple test to connect to the table and write the number of rows to a logfile.


这篇关于服务启动,但应用程序无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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