[英]C# Windows service SQL Server connection issue
On Windows Server 2012, I have created a C# Windows service which runs with a service account. 在Windows Server 2012上,我创建了一个使用服务帐户运行的C#Windows服务。
In constructor I am reading configuration from a SQL Server database using ADO.NET. 在构造函数中,我正在使用ADO.NET从SQL Server数据库中读取配置。
When I am trying to start the service, it fails with below exceptions. 当我尝试启动该服务时,它失败并显示以下异常。 After a few attempts to start the service, it is getting started.
尝试启动该服务几次后,它就开始了。
"The wait operation timed outconnection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement."
“等待操作超时的连接超时超时。尝试使用登录前握手确认时,超时时间已过。”
Below is the exception message from Logs 以下是日志中的异常消息
The wait operation timed outconnection Timeout Expired.
等待操作超时超时超时。 The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.
尝试使用登录前握手确认时,超时时间已过。
This could be because the pre-login handshake failed or the server was unable to respond back in time.这可能是因为登录前握手失败或服务器无法及时回复。
The duration spent while attempting to connect to this server was - [Pre-Login] initialization=21169;尝试连接到该服务器时所花费的时间为-[登录前]初始化= 21169; handshake=332;
握手= 332;
at system.Data.sqlclient.sqlinternalconnection.onError(sqlException exception, Boolean breakconnection, Action'l wrapcloseinAction)
在system.Data.sqlclient.sqlinternalconnection.onError(sqlException异常,布尔中断连接,Action'l wrapcloseinAction)
at System.在系统。 Data.
数据。 Sqlclient.TdsParser.ThrowExceptionAndwarning(TdsParserStateobject stateobj, Boolean callerHasconnectionLock, Boolean asyncclose)
Sqlclient.TdsParser.ThrowExceptionAndwarning(TdsParserStateobject stateobj,Boolean callerHasconnectionLock,布尔asyncclose)
at system.Data.sqlclient.TdsParserstateoblect.ReadsniError(TdsParserstateobject stateobj, unt32 error)在system.Data.sqlclient.TdsParserstateoblect.ReadsniError(TdsParserstateobject stateobj,unt32错误)
at system.Data.sqlclient.TdsParserstateoblect.ReadsnisyncoverAsync()在system.Data.sqlclient.TdsParserstateoblect.ReadsnisyncoverAsync()
at System.在系统。 Data.
数据。 Sqlclient.TdsParserStateob)ect.TryReadNetworkPacket()
Sqlclient.TdsParserStateob)ect.TryReadNetworkPacket()
at System.在系统。 Data.
数据。 Sqlclient.TdsParser.consumePreLoginiiandshake(Boolean encrypt, Boolean trustservercert, Boolean integratedsecurity, Boolean& marscapable)
Sqlclient.TdsParser.consumePreLoginiiandshake(布尔加密,布尔信任服务器证书,布尔集成安全性,布尔和可编组)
at system.Data.sqlclient.TdsParser.connect(serverinfo serverinfo, sqlinternalconnectionTds connHandler, Boolean ignoresniopenTimeout, 1nt64 timerExpire, Boolean encrypt, Boolean trustservercert, Boolean integratedsecurity, Boolean withFailover)在system.Data.sqlclient.TdsParser.connect(serverinfo serverinfo,sqlinternalconnectionTds connHandler,Boolean ignoresniopenTimeout,1nt64 timerExpire,布尔加密,布尔trustservercert,布尔集成安全性,布尔withFailover)
at system.Data.sqlclient.sqlinternalconnectionTds.AttemptoneLogin(serverinfo serverinfo, string newPassword, securestring newsecurePassword, Boolean ignoresniopenTimeout, TimeoutTimer timeout, Boolean withFailover)在system.Data.sqlclient.sqlinternalconnectionTds.AttemptoneLogin(serverinfo serverinfo,字符串newPassword,securestring newsecurePassword,布尔值ignoresniopenTimeout,TimeoutTimer超时,布尔值withFailover)
at system.Data.sqlclient.sqlinternalconnectionTds.LoginNoFailover(serverinfo serverinfo, string newPassword, securestring newsecurePassword, Boolean redirecteduserinstance, sqlconnectionstring connectionoptions, sqlcredential credential, TimeoutTimer timeout)在system.Data.sqlclient.sqlinternalconnectionTds.LoginNoFailover(serverinfo serverinfo,字符串newPassword,securestring newsecurePassword,布尔重定向用户实例,sqlconnectionstring连接选项,sqlcredential凭证,TimeoutTimer超时)
at system.Data.sqlclient.sglinternalconnectionTds.openLoginEnlist(TimeoutTimer timeout, sqlconnectionstring connectionoptions, sqlcredential credential, string newPassword, securestring newsecurePassword, Boolean redirecteduserinstance)在system.Data.sqlclient.sglinternalconnectionTds.openLoginEnlist(TimeoutTimer超时,sqlconnectionstring连接选项,sqlcredential凭证,字符串newPassword,securestring newsecurePassword,布尔重定向用户实例)
at system.Data.sqlclient.sqlinternalconnectionTds..ctor(DbconnectionPoolidentity identity, sqlconnectionstring connectionoptions, sqlcredential credential, object providerinfo, string newPassword, securestring newsecurePassword, Boolean redirecteduserinstance, sqlconnectionstring userconnectionoptions, sessionData reconnectsessionData)在system.Data.sqlclient.sqlinternalconnectionTds..ctor(DbconnectionPoolidentity身份,sqlconnectionstring连接选项,sqlcredential凭证,对象providerinfo,字符串newPassword,securestring newsecurePassword,布尔值重定向的用户实例,sqlconnectionstring用户连接选项,sessionData reconnectsessionData)
at system.Data.sqlclient.sqlconnectionFactory.createconnection(Dbconnectionoptions options, DbconnectionPoolKey poolKey, object poolGroupProviderinfo, DbconnectionPool pool, Dbconnection owningconnection, Dbconnectionoptions useroptions)在system.Data.sqlclient.sqlconnectionFactory.createconnection(Dbconnectionoptions选项,DbconnectionPoolKey poolKey,对象poolGroupProviderinfo,DbconnectionPool池,Dbconnection拥有的连接,Dbconnectionoptions用户选项)
at system.Data.ProviderBasembconnectionFactory.createPooledconnection(DbconnectionPool pool, Dbconnection owningobject, Dbconnectionoptions options, DbconnectionPoolKey poolKey, Dbconnectionoptions useroptions)在system.Data.ProviderBasembconnectionFactory.createPooledconnection(DbconnectionPool池,Dbconnection拥有对象,Dbconnectionoptions选项,DbconnectionPoolKey poolKey,Dbconnectionoptions用户选项)处
at system.Data.ProviderBasembconnectionPool.createobject(Dbconnection owningobject, Dbconnectionoptions useroptions, Dbconnectioninternal oldconnection)在system.Data.ProviderBasembconnectionPool.createobject(Dbconnection拥有对象,Dbconnectionoptions用户选项,Dbconnection内部旧连接)
at system.Data.ProviderBasembconnectionPool.usercreateRequest(Dbconnection owningobject, Dbconnectionoptions useroptions, Dbconnectioninternal oldconnection)在system.Data.ProviderBasembconnectionPool.usercreateRequest(Dbconnection拥有对象,Dbconnectionoptions用户选项,Dbconnection内部旧连接)
at system.Data.ProviderBasembconnectionPool.TryGetconnection(Dbconnection owningobject, uInt32 waitFormultipleobjectsTimeout, Boolean allowcreate, Boolean onlyonecheckconnection, Dbconnectionoptions useroptions, Dbconnectioninternal& connection)在system.Data.ProviderBasembconnectionPool.TryGetconnection(Dbconnection拥有对象,uInt32 waitFormultipleobjectsTimeout,布尔值allowcreate,布尔型onlyonecheckconnection,Dbconnectionoptions用户选项,Dbconnectioninternal&连接)
at system.Data.ProviderBase.DbconnectionPool.TryGetconnection(Dbconnection owningobject, Taskcompletionsource'l retry, Dbconnectionoptions useroptions, Dbconnectioninternal& connection)在system.Data.ProviderBase.DbconnectionPool.TryGetconnection(Dbconnection拥有对象,Taskcompletionsource'l重试,Dbconnectionoptions用户选项,Dbconnection内部和连接)
at system.Data.ProviderBasembconnectionFactory.TryGetconnection(Dbconnection owningconnection, Taskcompletionsource'l retry, Dbconnectionoptions useroptions, Dbconnectioninternal oldconnection, Dbconnectioninternal& connection)在system.Data.ProviderBasembconnectionFactory.TryGetconnection(Dbconnection拥有连接,Taskcompletionsource重试,Dbconnectionoptions用户选项,Dbconnection内部旧连接,Dbconnection内部内部和连接)
at system.Data.ProviderBase.Dbconnectioninternal.Tryopenconnectioninternal(Dbconnection outerconnection, DbconnectionFactory connectionFactory, Taskcompletionsource'l retry, Dbconnectionoptions useroptions) at system.Data.ProviderBasembconnectionclosed.Tryopenconnection(Dbconnection outerconnection, DbconnectionFactory connectionFactory, Taskcompletionsource'l retry, Dbconnectionoptions useroptions) at system.Data.sqlclient.sqlconnection.Tryopeninner(Taskcompletionsource'l retry) at system.Data.sqlclient.sqlconnection.Tryopen(Taskcompletionsource'l retry) at system.Data.sqlclient.sqlconnection.open()在system.Data.ProviderBasembconnectionclosed.Tryopenconnection(Dbconnection外连接,DbconnectionFactory connectionFactory,Taskcompletionsource'l重试,Dbconnectionoptions系统选项) .data.sqlclient.sqlconnection.Tryopeninner(Taskcompletionsource'l重试)在系统.Data.sqlclient.sqlconnection.Tryopen(Taskcompletionsource'l重试)在system.Data.sqlclient.sqlconnection.open()
Issue resolved after adding "MultiSubnetFailover=True" in connection string 在连接字符串中添加“ MultiSubnetFailover = True”后已解决问题
Thanks everyone for help. 谢谢大家的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.