# Sql Server Deadlock

**URL:** https://www.finalbuilder.com/forums/t/sql-server-deadlock/5720
**Category:** Bugs
**Created:** [September 13, 2012, 2:47am UTC](https://www.finalbuilder.com/forums/t/sql-server-deadlock/5720 "2012-09-13T02:47:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jenasys](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/jenasys/32/888_2.png) [@Jenasys](https://www.finalbuilder.com/forums/u/Jenasys)
#### Post date: [September 13, 2012, 2:47am UTC](https://www.finalbuilder.com/forums/t/sql-server-deadlock/5720/1 "2012-09-13T02:47:55Z")

</div>

Last night my server backup process ran into the continua server project I was working on. It looks like that build process generated a SQL Server deadlock and then the whole web application has gone into melt down mode.&nbsp; I'm attempting to re-start the services and find out what's happened (server has also triggered a crash), so I'm not sure the exact source of this issue.

I've had to extract this directly from the SQL Server database.

# Exception: GenericADOException

Message: could not execute query  
[SELECT TOP (@p0) Id5\_, SourceEn2\_5\_, SourceEn3\_5\_, SourceEn4\_5\_, Date5\_, Message5\_, Hash5\_, Importance5\_, messaget9\_5\_, RepeatC10\_5\_, Resolved5\_ FROM (select event0\_.Id as Id5\_, event0\_.SourceEntityId as SourceEn2\_5\_, event0\_.SourceEntityTypeId as SourceEn3\_5\_, event0\_.SourceEntityName as SourceEn4\_5\_, event0\_.Date as Date5\_, event0\_.Message as Message5\_, event0\_.Hash as Hash5\_, event0\_.Importance as Importance5\_, event0\_.messagetype as messaget9\_5\_, event0\_.RepeatCount as RepeatC10\_5\_, event0\_.Resolved as Resolved5\_, ROW\_NUMBER() OVER(ORDER BY event0\_.Resolved, event0\_.Date DESC) as \_\_hibernate\_sort\_row from core\_event event0\_) as query WHERE query.\_\_hibernate\_sort\_row \> @p1 ORDER BY query.\_\_hibernate\_sort\_row]  
&nbsp; Name:p1 - Value:0&nbsp; Name:p2 - Value:20  
[SQL: SELECT TOP (@p0) Id5\_, SourceEn2\_5\_, SourceEn3\_5\_, SourceEn4\_5\_, Date5\_, Message5\_, Hash5\_, Importance5\_, messaget9\_5\_, RepeatC10\_5\_, Resolved5\_ FROM (select event0\_.Id as Id5\_, event0\_.SourceEntityId as SourceEn2\_5\_, event0\_.SourceEntityTypeId as SourceEn3\_5\_, event0\_.SourceEntityName as SourceEn4\_5\_, event0\_.Date as Date5\_, event0\_.Message as Message5\_, event0\_.Hash as Hash5\_, event0\_.Importance as Importance5\_, event0\_.messagetype as messaget9\_5\_, event0\_.RepeatCount as RepeatC10\_5\_, event0\_.Resolved as Resolved5\_, ROW\_NUMBER() OVER(ORDER BY event0\_.Resolved, event0\_.Date DESC) as \_\_hibernate\_sort\_row from core\_event event0\_) as query WHERE query.\_\_hibernate\_sort\_row \> @p1 ORDER BY query.\_\_hibernate\_sort\_row]  
Stack Trace:&nbsp;&nbsp;&nbsp; at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)  
&nbsp;&nbsp; at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)  
&nbsp;&nbsp; at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters)  
&nbsp;&nbsp; at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters)  
&nbsp;&nbsp; at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results)  
&nbsp;&nbsp; at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results)  
&nbsp;&nbsp; at NHibernate.Impl.AbstractSessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters)  
&nbsp;&nbsp; at NHibernate.Impl.ExpressionQueryImpl.List()  
&nbsp;&nbsp; at NHibernate.Linq.DefaultQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)  
&nbsp;&nbsp; at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)  
&nbsp;&nbsp; at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)  
&nbsp;&nbsp; at Remotion.Linq.QueryableBase`1.GetEnumerator()  
&nbsp;&nbsp; at System.Linq.Buffer`1..ctor(IEnumerable`1 source)  
&nbsp;&nbsp; at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)  
&nbsp;&nbsp; at Continua.Logging.EventManager.GetEvents(Paging paging)  
&nbsp;&nbsp; at Continua.Services.CoreService.GetEvents(Paging paging)  
&nbsp;&nbsp; at SyncInvokeGetEvents(Object , Object[] , Object[] )  
&nbsp;&nbsp; at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)  
&nbsp;&nbsp; at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)  
&nbsp;&nbsp; at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)  
&nbsp;&nbsp; at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)  
&nbsp;&nbsp; at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

# Exception: SqlException

Message: **Transaction (Process ID 61) was deadlocked on lock resources with another process and has been chosen as the deadlock victim**. Rerun the transaction.  
Stack Trace:&nbsp;&nbsp;&nbsp; at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)  
&nbsp;&nbsp; at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)  
&nbsp;&nbsp; at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)  
&nbsp;&nbsp; at System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)  
&nbsp;&nbsp; at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)  
&nbsp;&nbsp; at System.Data.SqlClient.SqlDataReader.Read()  
&nbsp;&nbsp; at NHibernate.Driver.NHybridDataReader.Read()  
&nbsp;&nbsp; at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)  
&nbsp;&nbsp; at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)  
&nbsp;&nbsp; at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)

# Web site result

&nbsp;

![ContinuaCI_874_DB_Server_crash.jpg](https://www.finalbuilder.com/forums/uploads/default/original/2X/1/10f16967efebd09f32d8bc78a93239be56874d9f.jpeg)

# Event log

Could not initialise database:  
  
System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)  
&nbsp;&nbsp; at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)  
&nbsp;&nbsp; at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)  
&nbsp;&nbsp; at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover)  
&nbsp;&nbsp; at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)  
&nbsp;&nbsp; at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)  
&nbsp;&nbsp; at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)  
&nbsp;&nbsp; at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions)  
&nbsp;&nbsp; at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)  
&nbsp;&nbsp; at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)  
&nbsp;&nbsp; at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions)  
&nbsp;&nbsp; at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions)  
&nbsp;&nbsp; at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)  
&nbsp;&nbsp; at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)  
&nbsp;&nbsp; at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)  
&nbsp;&nbsp; at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)  
&nbsp;&nbsp; at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)  
&nbsp;&nbsp; at System.Data.SqlClient.SqlConnection.Open()  
&nbsp;&nbsp; at FluentMigrator.Runner.Processors.SqlServer.SqlServerProcessor..ctor(IDbConnection connection, IMigrationGenerator generator, IAnnouncer announcer, IMigrationProcessorOptions options, IDbFactory factory)  
&nbsp;&nbsp; at FluentMigrator.Runner.Processors.SqlServer.SqlServer2008ProcessorFactory.Create(String connectionString, IAnnouncer announcer, IMigrationProcessorOptions options)  
&nbsp;&nbsp; at FluentMigrator.Runner.Initialization.TaskExecutor.InitializeProcessor(String assemblyLocation)  
&nbsp;&nbsp; at FluentMigrator.Runner.Initialization.TaskExecutor.Initialize()  
&nbsp;&nbsp; at FluentMigrator.Runner.Initialization.TaskExecutor.Execute()  
&nbsp;&nbsp; at Continua.Migrations.Runner.Execute(String database, String connectionString, String fileName)  
&nbsp;&nbsp; at Continua.Server.Service.Migrator.Begin()  
ClientConnectionId:00000000-0000-0000-0000-000000000000  
Exiting...

---

<div class="post-metadata">

### Author: ![vinnie](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/v/71e660/32.png) [@vinnie](https://www.finalbuilder.com/forums/u/vinnie)
#### Post date: [September 14, 2012, 8:30am UTC](https://www.finalbuilder.com/forums/t/sql-server-deadlock/5720/2 "2012-09-14T08:30:29Z")

</div>

What were the sequence of events here?   
  
 The Configuration was executed at some point.   
 The build started.   
 There was a dead lock somewhere.   
 Continua server service crashed.   
 You restarted the service and got the ‘Could not initialise database’

---

<div class="post-metadata">

### Author: ![Jenasys](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/jenasys/32/888_2.png) [@Jenasys](https://www.finalbuilder.com/forums/u/Jenasys)
#### Post date: [September 17, 2012, 12:39pm UTC](https://www.finalbuilder.com/forums/t/sql-server-deadlock/5720/3 "2012-09-17T12:39:14Z")

</div>

Yes that seems to be the correct order of things that triggered the deadlock.&nbsp; I hope there is enough information in the stack trace to find the location of the code that's triggering it.

I might try and run screen recording software over the next set of releases, so you guys can see the order of events.

---

<div class="post-metadata">

### Author: ![vinnie](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/v/71e660/32.png) [@vinnie](https://www.finalbuilder.com/forums/u/vinnie)
#### Post date: [September 17, 2012, 1:31am UTC](https://www.finalbuilder.com/forums/t/sql-server-deadlock/5720/4 "2012-09-17T01:31:44Z")

</div>

The stack trace is showing a strange area of code for the original problem so it’s pretty hard to track down. We’ll keep an eye on this one. Is it frequently happening for you?

---

<div class="post-metadata">

### Author: ![Jenasys](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/jenasys/32/888_2.png) [@Jenasys](https://www.finalbuilder.com/forums/u/Jenasys)
#### Post date: [September 17, 2012, 1:55am UTC](https://www.finalbuilder.com/forums/t/sql-server-deadlock/5720/5 "2012-09-17T01:55:10Z")

</div>

No, it has only happened once, so I suspect a PEBKAC issue. As a software developer, I know deadlocks are very bad news, so that’s why I reported it.
