question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Revisit the sp_releaseapplock for SQL Server connections

See original GitHub issue

Evolve migrate with SQL Server throws the following error during build and run time:

Cannot release the application lock (Database Principal: ‘public’, Resource: ‘Evolve’) because it is not currently held. Sql query: sp_releaseapplock Cannot release the application lock (Database Principal: ‘public’, Resource: ‘Evolve’) because it is not currently held. at Evolve.WrappedConnectionEx.Execute[T](WrappedConnection wrappedConnection, String sql, Func2 query, Action1 setupDbCommand) at Evolve.WrappedConnectionEx.ExecuteDbCommand[T](WrappedConnection wrappedConnection, String sql, Action1 setupDbCommand, Func2 query) at Evolve.Dialect.SQLServer.SQLServerDatabase.ReleaseApplicationLock() at Evolve.Evolve.InternalExecuteCommand(Action`1 commandAction) at Evolve.Evolve.Migrate() at Evolve.Evolve.ExecuteCommand() at Evolve.MsBuild.EvolveBoot.Execute()

This is happening in SQL Server 2012

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lecailloncommented, Feb 26, 2021

Thanks a lot @sergiu-svinarciuc ! That’s a serious lead. I think you’re right. And it explains why my current SQL Server tests work, because I do not change of database in my scripts V3_1 and V_3_1_1. I use the fully qualified table name to create and insert data in the new created database.

I will investigate in next days what we can do about it. And again your proposal seems legit. I just want to try to change database in a migration configured with the option : EnableClusterMode = false Consequenses will be no node synchronization at migration time (no database lock). But for some scenario it won’t be an issue.

I’ll keep you in touch Sergiu. Thanks again

1reaction
sergiu-svinarciuccommented, Feb 26, 2021

Hey @lecaillon , first of all thank you so much for a great tool!

The root cause of the issues above, most probably, is the usage of “use [database]” statement, specifically when this one is not consistent with the target DB provided in the connection string. In such case, when Evolve is done with applying the patch, it tries to release the lock in a different context because of the “use” statement.

There is also a nasty side effect. Evolve reports back in console that the patch has been applied successfully (and the changes are actually applied) instead of doing a rollback (which I believe it can’t do because of the switched context again). Also, the patch is not registered in the changelog table.

Would it make sense to add a safety-net and fail the migration if the patch contains a “use” statement?

Happy to contribute in any ways, let me know your thoughts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure the user connections (server configuration option)
This topic describes how to set the user connections server configuration option in SQL Server by using SQL Server Management Studio or ...
Read more >
Configure remote access (server configuration option)
Use SQL Server Management Studio · In Object Explorer, right-click a server and select Properties. · Select the Connections node. · Under Remote ......
Read more >
How to connect to a remote SQL Server
In this article, we will explain step by step how to connect remotely to a SQL Server Express instance with two types of...
Read more >
Connect to Microsoft SQL Server from ArcGIS ...
Right-click Databases and click New Database Connection. Choose SQL Server from the Database Platform drop-down list. Type the SQL Server instance name ...
Read more >
Create a Microsoft SQL Server connection
Once you have created a connection to a Microsoft SQL Server database, you can select data from the available tables and then load...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found