计算机重启时服务启动问题 [英] Service start issue on Computer restart

查看:63
本文介绍了计算机重启时服务启动问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用VB.NET开发的Windows服务,一旦服务启动就会尝试连接到

数据库。当我手动启动

服务时没有问题 - 但是当我重新启动托管服务的计算机时,我尝试连接到
时会出现Null Reference Exception数据库(我有

设置服务自动启动)。有什么想法会发生这种情况吗?


提前致谢。


Ajay Mirmira

I have a Windows Service developed in VB.NET that attempts to connect to a
database as soon as the service starts. I have no problem when I start the
service manually - but when I restart the computer that hosts the service, I
get a Null Reference Exception when I try to connect to the database (I have
set the service to start automatically). Any ideas why this is happening?

Thanks in advance.

Ajay Mirmira

推荐答案

您的代码中是否抛出了NullReferenceException(您必须修复的错误)

或.NET Framework内部?


-


Carlos J. Quintero


MZ-Tools 4.0:Visual Studio .NET的生产力插件

您可以更快地编码,设计和记录。
http://www.mztools。 com

" amirmira" <上午****** @ discussions.microsoft.com> escribióenel mensaje

新闻:D2 ********************************** @ microsof t.com ...
Is the NullReferenceException thrown in your code (a bug that you must fix)
or inside the .NET Framework?

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
"amirmira" <am******@discussions.microsoft.com> escribió en el mensaje
news:D2**********************************@microsof t.com...
我有一个用VB.NET开发的Windows服务,一旦服务启动就会尝试连接到数据库。当我手动启动
服务时没有问题 - 但是当我重新启动托管服务的计算机时,当我尝试连接数据库时,我得到一个Null Reference Exception(I
将服务设置为自动启动)。有什么想法会发生这种情况吗?

提前致谢。

Ajay Mirmira
I have a Windows Service developed in VB.NET that attempts to connect to a
database as soon as the service starts. I have no problem when I start the
service manually - but when I restart the computer that hosts the service,
I
get a Null Reference Exception when I try to connect to the database (I
have
set the service to start automatically). Any ideas why this is happening?

Thanks in advance.

Ajay Mirmira



它是可能是在SQL服务器启动之前启动了您的服务。

您可以设置服务以依赖正在启动的其他服务

优先。您可以查看。

It is possible that your service is being started before SQL server is.
You can set you service to depend on other services being started
first. You might look into that.


您需要验证您是否有网络连接。

如果服务之前启动网络启动并运行你会得到

一个execption错误。


如果你无法解决它...一个奇怪的方法是<服务启动时,
..

..将计时器暂停5分钟。

Private tmr As New System.Timers。定时器(5000)

私有tmrstart作为DateTime


Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load


tmrstart =现在


AddHandler tmr.Elapsed,AddressOf tmr_tick


tmr.Start()


End Sub


Private Sub tmr_tick(ByVal sender As Object,ByVal e如
System.Timers.ElapsedEventArgs)


If(DateDiff(DateInterval.Minute,Now,DateAdd(DateInterval.Minute,5,

tmrstart),FirstDayOfWeek.Sunday)< = 0)然后


MsgBox(5分钟以上)


tmr.Stop()


''你需要把你的函数调用到这里


结束如果


结束子


就像我说的那样很难得,但它会让你解决问题,直到

你可以算出来out。


你得到一个execption错误似乎很奇怪。它必须是

,你打电话的东西还没有。

如果你正在调用数据库并且尚未启动它你将是

无法连接,所以这不是问题。


似乎在你遇到这个问题之前就已经发生了


发布服务启动代码。这可能会有所帮助


Chris


" Carlos J. Quintero [.NET MVP]" < CA ***** @ NOSPAMsogecable.com>写在

消息新闻:好的************* @ TK2MSFTNGP14.phx.gbl ...
you need to verify that you have a network connection.
If the service is starting before the network is up and running you will get
an execption error.

if you can not figure it out... a hoky way around it is
..
when the service is started.. put a timer that pauses it for 5 mins.
Private tmr As New System.Timers.Timer(5000)

Private tmrstart As DateTime

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

tmrstart = Now

AddHandler tmr.Elapsed, AddressOf tmr_tick

tmr.Start()

End Sub

Private Sub tmr_tick(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)

If (DateDiff(DateInterval.Minute, Now, DateAdd(DateInterval.Minute, 5,
tmrstart), FirstDayOfWeek.Sunday) <= 0) Then

MsgBox("5 mins up")

tmr.Stop()

''you need to put your function call here

End If

End Sub

Like i said it is hoky as hell but it will get you around your problem until
you can figure it out.

It seems really strange that your getting an execption error. It has to be
that your calling something that is not there yet.
If you were calling database and it has not been started yet you would be
getting an unable to connect so that is not the issues.

It seems to be happening before you get to that issue

Post you service startup code. That might help

Chris

"Carlos J. Quintero [.NET MVP]" <ca*****@NOSPAMsogecable.com> wrote in
message news:Ok*************@TK2MSFTNGP14.phx.gbl...
你的NullReferenceException是否被抛出代码(你必须修复的bug)或.NET Framework内部的代码?



Carlos J. Quintero

MZ-Tools 4.0:Visual Studio .NET的生产力插件
您可以更快地编码,设计和记录。
http://www.mztools.com

" amirmira" <上午****** @ discussions.microsoft.com> escribióenel mensaje
新闻:D2 ********************************** @ microsof t.com ...
Is the NullReferenceException thrown in your code (a bug that you must
fix) or inside the .NET Framework?

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
"amirmira" <am******@discussions.microsoft.com> escribió en el mensaje
news:D2**********************************@microsof t.com...
我在VB.NET中开发了一个Windows服务,一旦服务启动,就会尝试连接到数据库。当我手动启动
服务时没有问题 - 但是当我重新启动承载
服务的计算机时,当我尝试连接时,我得到一个空引用异常数据库(我
已设置服务自动启动)。有什么想法会发生这种情况吗?

提前致谢。

Ajay Mirmira
I have a Windows Service developed in VB.NET that attempts to connect to a
database as soon as the service starts. I have no problem when I start
the
service manually - but when I restart the computer that hosts the
service, I
get a Null Reference Exception when I try to connect to the database (I
have
set the service to start automatically). Any ideas why this is happening?

Thanks in advance.

Ajay Mirmira




这篇关于计算机重启时服务启动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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