Windows服务异常自动关闭

Posted charles-jiang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Windows服务异常自动关闭相关的知识,希望对你有一定的参考价值。

一个Windows服务程序,在其他服务器运行都是正常的,今天在新服务器中运行,出现未知异常。

1.查看系统日志:自定义视图--管理日志
2.日志内容,比如
- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name=".NET Runtime" /> 
  <EventID Qualifiers="0">1026</EventID> 
  <Level>2</Level> 
  <Task>0</Task> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2018-10-09T02:29:41.000000000Z" /> 
  <EventRecordID>499672</EventRecordID> 
  <Channel>Application</Channel> 
  <Computer>WIN-N6Q3A4U468A</Computer> 
  <Security /> 
  </System>
- <EventData>
  <Data>Application: LgWinService.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.AccessViolationException Stack: at SNINativeMethodWrapper.SNIClose(IntPtr) at System.Data.SqlClient.SNIHandle.ReleaseHandle() at System.Runtime.InteropServices.SafeHandle.InternalDispose() at System.Runtime.InteropServices.SafeHandle.Dispose(Boolean) at System.Runtime.InteropServices.SafeHandle.Dispose() at System.Data.SqlClient.TdsParserStateObject.Dispose() at System.Data.SqlClient.TdsParser.Disconnect() at System.Data.SqlClient.SqlInternalConnectionTds.LoginFailure() at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(System.Data.ProviderBase.TimeoutTimer, System.Data.SqlClient.SqlConnectionString, System.Data.SqlClient.SqlCredential, System.String, System.Security.SecureString, Boolean) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(System.Data.ProviderBase.DbConnectionPoolIdentity, System.Data.SqlClient.SqlConnectionString, System.Data.SqlClient.SqlCredential, System.Object, System.String, System.Security.SecureString, Boolean, System.Data.SqlClient.SqlConnectionString, System.Data.SqlClient.SessionData) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(System.Data.Common.DbConnectionOptions, System.Data.Common.DbConnectionPoolKey, System.Object, System.Data.ProviderBase.DbConnectionPool, System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(System.Data.ProviderBase.DbConnectionPool, System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions, System.Data.Common.DbConnectionPoolKey, System.Data.Common.DbConnectionOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(System.Data.Common.DbConnection, UInt32, Boolean, Boolean, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal ByRef) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(System.Data.Common.DbConnection, System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal ByRef) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(System.Data.Common.DbConnection, System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal, System.Data.ProviderBase.DbConnectionInternal ByRef) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>) at System.Data.SqlClient.SqlConnection.TryOpen(System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>) at System.Data.SqlClient.SqlConnection.Open() at Dos.ORM.Database.CreateConnection(Boolean) at Dos.ORM.Database.ExecuteReader(System.Data.Common.DbCommand) at Dos.ORM.Section.ToDataReader() at Dos.ORM.Section.ToList[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]() at DAL.DBModelDAL.Base_SchoolDAL.GetAllFromBaseView() at BLL.DBModelBLL.Base_DataBLL.InitResSubjectFirst() at LgBigData.WinService.QuartzJob.BaseDataJob.Execute(Quartz.IJobExecutionContext) at Quartz.Core.JobRunShell.Run() at Quartz.Simpl.SimpleThreadPool+WorkerThread.Run() at System.Threading.ThreadHelper.ThreadStart_Context(System.Object) at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Threading.ThreadHelper.ThreadStart()</Data> 
  </EventData>
  </Event>

3.确定问题:?System.Data.SqlClient?的问题。

微软官方回答:

https://support.microsoft.com/zh-cn/help/2915689/applications-crash-and-accessviolationexception-exception-occurs-when

?https://support.microsoft.com/en-us/help/2915689/applications-crash-and-accessviolationexception-exception-occurs-when

4.解决方法

卸载.NET 4.5.1或者升级.NET

不推荐使用.NET 4.5.1

 

Resolution


To resolve this issue, upgrade the .NET Framework 4.5.1 to the Microsoft .NET Framework 4.5.2 .

 



















以上是关于Windows服务异常自动关闭的主要内容,如果未能解决你的问题,请参考以下文章

将java程序注册成windows服务自启动并异常退出自动重启

将java程序注册成windows服务自启动并异常退出自动重启

将java程序注册成windows服务自启动并异常退出自动重启

使用PowerShell关闭Windows更新服务和自动更新Windows 10

windows10系统关闭自动更新服务

怎么关闭windows server 2016自动更新