Error: Couldn't get write lock

Getting these errors frequently recently.  Usually a refresh will be successful.  Anyone know what the problem is?  Running latest available version of SSC and SSMS 18.9.2.




Tagged:

Answers


  • I'm sorry you are experiencing this issue with SQL Source Control. Thanks for reaching out to us on this!

    I think initially it's worth having a look at any antivirus software you are using and try excluding the %localappdata%\Red Gate\SQL Source Control 7 directory from any scans. If your antivirus is scanning a file and obtaining a write lock, that could be causing the error you are experiencing.

    If this doesn't fix this issue for you, would it be possible to get a copy of the log file (https://documentation.red-gate.com/soc7/troubleshooting/logging-and-log-files)?






    Kind regards

    Dan Jary | Redgate Software
    Have you visited our Help Center?
  • @Dan_J - Thanks for the reply.

    I have added "C:\Users\my_user_name\AppData\Local\Red Gate\SQL Source Control 7" to my Microsoft Defender exclusions.  I'll monitor and see if the issue comes up again - if so, I'll send logs.
  • @Dan_J - Got an error after adding the exclusion.  Following is the applicable error message from the logs:

    <div>2021-09-15 07:35:56.989 -07:00|Error|RedGate.SQLSourceControl.CommonUI.Controls.CancellableControl`2[[RedGate.SQLSourceControl.Engine.Diff.IChangeSetWithWorkspace, RedGate.SQLSourceControl.Engine, Version=7.2.35.13078, Culture=neutral, PublicKeyToken=7f465a1c156d4d57],[RedGate.SQLSourceControl.CommonUI.Controls.DifferencesViewerControl, RedGate.SQLSourceControl.CommonUI, Version=7.2.35.13078, Culture=neutral, PublicKeyToken=7f465a1c156d4d57]]|77| An exception occurred whilst performing an operation</div><div>System.TimeoutException: Couldn't get write lock</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.PersistentWorkspace.UpgradeToWriteLock(ICancellableOperationStatus status)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.PersistentWorkspace.<>c__DisplayClass9_0.<UpgradeAll>b__0(ICancellableOperationStatus status)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.NamedOperation.Operation(ICancellableOperationStatus cancellableOperation)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.CancellableOperation.<Invoke>b__9_0()</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.CancellableOperationBase.PerformAction(Action action)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.CancellableOperationBase.InvokeWithTracker(Action action)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.CancellableOperation.Invoke()</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.SharedUtilsUtils.DoActionWithCancel(ICancellableOperationStatus status, ICancellable cancellable, Action action)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.SharedUtilsUtils.DoActionWithStatus(ICancellableOperationStatus status, ICancellable cancellable, Action action)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.MultiStepCancellableOperation`1.ExecuteAsOnOperation(ICancellableOperationStatus status)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.MultiStepCancellableOperationWithPostTask`1.ExecuteAsOnOperation(ICancellableOperationStatus status)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Diff.DiffBuilding.NoOpsResolver.ResolveNoOps(IFilterConfigDiffCreator filterConfigDiffCreator, Boolean compareConfigIsNoOp, Boolean isPreScriptNoOp, Boolean isPostScriptNoOp, DatabaseObjectIdSet dataNoOpIds, DatabaseObjectIdSet schemaNoOps, IThreeWayDiffSession threeWayDiffSession, List`1 changes, ITransientWorkspace transientWorkspace)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Diff.DiffBuilding.ToCommitAndRetrieveChangeSetCreator.RetrieveNoOpChanges(DatabaseObjectIdSet schemaNoOpIds, DatabaseObjectIdSet dataNoOpIds, Boolean preScriptNoOp, Boolean postScriptNoOp)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Diff.DiffBuilding.ToCommitAndRetrieveChangeSetCreator.ResolveTheseNoOps(Boolean isCompareConfigNoOp, Boolean isPreScriptNoOp, Boolean isPostScriptNoOp, DatabaseObjectIdSet schemaNoOpIds, DatabaseObjectIdSet dataNoOpIds)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Diff.DiffBuilding.ToCommitAndRetrieveChangeSetCreator.ResolveAnyNoOps(ICancellableOperationStatus status, SourceControlOperation sourceControlOperation)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Diff.DiffBuildSessions.DiffBuilder.GetChangeSetResolvingNoOps[T](String source, IBoundDatabase boundDatabase, IChangeSetFactory`1 changeSetFactory, ICancellableOperationStatus status, SourceControlOperation sourceControlOperation)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Diff.DiffBuildSessions.DiffBuilder.BuildToCommitChangeSet(IBoundDatabase boundDatabase, ICancellableOperationStatus status)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Diff.BoundDatabase.GetNewCommitableChanges(ICancellableOperationStatus status)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Diff.BoundDatabase.<>c__DisplayClass25_0.<GetCancellableCommitableChanges>b__0(ICancellableOperationStatus status)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.MutexedCancellableOperation`1.<>c__DisplayClass7_0.<Invoke>b__0()</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.CancellableOperationBase.PerformAction(Action action)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.CancellableOperationBase.InvokeWithTracker(Action action)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.MutexedCancellableOperation`1.Invoke()</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.Task.CancellableOperationTypeConverter`2.Invoke()</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.CommonUI.Controls.CancellableControl`2.<>c__DisplayClass30_0.<InvokeOperation>b__1()</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.Engine.Utils.ErrorReporting.ErrorReporterBase.Do(Action toDo, Predicate`1 isFatalPredicate, Boolean rethrow)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.CommonUI.ErrorHandling.SaErrorReporter.DoWithObviousExceptionsRethrowAll(Action action)</div><div>&nbsp; &nbsp;at RedGate.SQLSourceControl.CommonUI.Controls.CancellableControl`2.InvokeOperation(ICancellableOperation`1 operation, Object token)</div>
  • Any update on this?  I'm still getting this error frequently.

  • My apology for the delay in coming back to you on this.

    Thanks for checking your MS Defender exclusions, I'm sorry this didn't resolve the issue you are seeing here!

    I've been doing some further research into the 'Couldn't get write lock' error. Aside from antivirus software exceptions, this error often surfaces when SQL Source Control can't get a lock on the local working copies of the files that it uses. For most occasions simply restarting SSMS fixes this issue, however I'm guessing this is something you will have done at least once since encountering this issue?

    Additionally, Process Monitor from Windows Sysinternals may help you find out if any other process has got a lock on the SQL Source Control files.


    Kind regards

    Dan Jary | Redgate Software
    Have you visited our Help Center?
  • @Dan_J Yes, I shut down my computer every night. I've also seen the issue on my secondary computer which does not shut down at night but I close SSMS at the end of the day and start up SSMS fresh every day that I use it there. 

    Curious as to what are the specific files it's trying to get a lock on, and why is trying to write when it's looking for differences? This is only happening after I click on a database and I'm waiting for SSC to find any pending changes. If it matters, we use the shared development model. 
  • Hello. I just came to say that I also get the same error very frequently since the last version update of Source Control.
  • Hi,

    @pablolerner thanks for mentioning that you are also seeing this error.

    We are investigating if this is affecting specific versions of SQL Source Control, I will confirm on this as soon as possible.

    In the mean time, could you please update to the very latest version of SQL Source Control (v.7.2.48) to confirm if you continue to experience this error in that version?  https://download.red-gate.com/checkforupdates/SQLSourceControl/SQLSourceControl_7.2.48.13814.exe

    Kind regards

    Dan Jary | Redgate Software
    Have you visited our Help Center?
  • @Dan_J - I updated to 7.2.48.13814 and continue to see the error.
  • Hi,

    I have been speaking with our development team on this again, they have asked for some further information on this if possible:

    When you next see this error, would it be possible for you to use a tool such as LockHunter (https://lockhunter.com/) to see if this gives any indication into why this error is occurring?

    Also, would it be possible for you to provide the SQL Source Control debug log files (https://documentation.red-gate.com/soc/troubleshooting/logging-and-log-files)? They contain information around each time SQL Source Control acquires or releases a lock on the transient.



    Kind regards

    Dan Jary | Redgate Software
    Have you visited our Help Center?
  • Hi. I send you my last two log files at the time the error show up. I was just editing a script file in SSMS

  • Thank you for the log files you provided.

    While we continue to investigate this, I just wanted to check if you had been able to use a tool such as LockHunter (https://lockhunter.com/) to see if this gives any indication into why this error is occurring?

    Kind regards

    Dan Jary | Redgate Software
    Have you visited our Help Center?
  • Hi. Yes, it indicated SQL Server Management Studio as the application locking. Nothing else. No other information
  • Hi,

    I have been discussing this with our development team, we have also been attempting to reproduce this issue but have still so far been unsuccessful. We are determined to achieve a successful reproduction of this issue but believe we will need some further information in order to achieve this:

    • Does this error occur during every refresh?
    • Does it happen when switching from one database to another?
    • Were there any pending changes on the database?
    • Were there any changes on the linked TFS repository?
    • Does it only reproduce on one/certain database(s), or can reproduce it on any database?
    • Does it only happen with TFS repository (does it still occur when using git or working folder)?

    Also, there has been a suggestion that a change included in SQL Source Control v.7.2.32 could possibly be causing this issue. Are you able try using the previous version (v7.2.31 - https://download.red-gate.com/checkforupdates/SQLSourceControl/SQLSourceControl_7.2.31.12796.exe) and then v7.2.32 (https://download.red-gate.com/checkforupdates/SQLSourceControl/SQLSourceControl_7.2.32.12853.exe) to see if you see this same issue in both versions?




    Kind regards

    Dan Jary | Redgate Software
    Have you visited our Help Center?
  • Hi Dan, here are your answers:

    • Does this error occur during every refresh?
    No. Only sometimes.
    • Does it happen when switching from one database to another?
    No, usually when refreshing SQL Source Control window. Although a few times when working in code, in a Stored Procedure, with all SQL Source Control windows open. 
    • Were there any pending changes on the database?
    Yes. There always are some
    • Were there any changes on the linked TFS repository?
    Yes. There always are some
    • Does it only reproduce on one/certain database(s), or can reproduce it on any database?
    Any Database
    • Does it only happen with TFS repository (does it still occur when using git or working folder)?
    We only use TFS



  • Does this error occur during every refresh?
    No - I'd estimate about 25% of the time

    Does it happen when switching from one database to another?
    Yes, sometimes

    Were there any pending changes on the database?
    Sometimes yes and sometimes no - seems unrelated to pending changes

    Were there any changes on the linked TFS repository?
    Sometimes yes and sometimes no - seems unrelated

    Does it only reproduce on one/certain database(s), or can reproduce it on any database?
    Happens on any databases

    Does it only happen with TFS repository (does it still occur when using git or working folder)?
    Like @pablolerner, we only use TFS because this is a restriction to use SSC in the Shared Dev Model.

    I've been busy lately, but when I get some time I will try 7.2.31 to see if it's any different.  Thanks @pablolerner for testing with the LockHunter application - I'm not able to install unknown 3rd party software on my company machine without jumping through hoops.
  • Hi,

    Thank you both for coming back on this.

    I am continuing to engage with our development team on this.

    @[email protected]_TABLE_Students - if you could please let me know if you continue to see this issue in 7.2.31, that would be greatly appreciated.
    Kind regards

    Dan Jary | Redgate Software
    Have you visited our Help Center?

  • I just wanted to check if you have been able to check if you continue to see this issue in v.7.2.31 (https://download.red-gate.com/checkforupdates/SQLSourceControl/SQLSourceControl_7.2.31.12796.exe)?

    Kind regards

    Dan Jary | Redgate Software
    Have you visited our Help Center?
  • Hello,

    I have been discussing this with our development team who are continuing to look into this issue.

    They have asked if you could please navigate to C:\Program Files (x86)\Red Gate\SQL Source Control 7, take a copy/backup the RedGate.SQLSourceControl.Engine.dll file and temporarily replace it with the one attached to see if you continue to experience this issue. 

    Just to mention that you may notice a decrease in application performance while the temporary .dll file is in place.

    After you have performed this test please restore the original file.





    Kind regards

    Dan Jary | Redgate Software
    Have you visited our Help Center?
  • Sure, let me try this.
  • I have tried to replace the engine file with the one you send but I get this error and SQL Source Control just does not work. I just restored the original engine file and it works again.
    The log file referenced in this message does not exists, could not find it.


  • Thanks for your update on this.

    I have just learned that the file may be protected and so require unlocking, as shown in the example below:




    Kind regards

    Dan Jary | Redgate Software
    Have you visited our Help Center?
  • Dan_J said:

    I just wanted to check if you have been able to check if you continue to see this issue in v.7.2.31 (https://download.red-gate.com/checkforupdates/SQLSourceControl/SQLSourceControl_7.2.31.12796.exe)?

    Hi @Dan_J

    Sorry this took so long to get to.

    I was not able to replicate the issue in 7.2.31.
    I was able to replicate the issue in 7.2.32.

    Hope this helps narrow down the root cause.
  • @Dan_J - any updates?
  • @Dan_J or anyone at Redgate - could we please get an update on this issue?  It's been almost 8 months since reported and it continues to be an issue.
Sign In or Register to comment.