THE PROCESS CANNOT ACCESS THE FILE ‘SQLAGTCTR.DLL’ OR ‘SQAGTRES.DLL’ BECAUSE IT IS BEING USED BY ANOTHER PROCESS.
When trying to upgrade SQL Server 2008 R2 SP1 to SP2 it failed with error. Following is a part of the Summary:
Final result: The patch installer has failed to update the following instance: MSSQLSERVER. To determine the reason for failure, review the log files.
Exit code (Decimal): -2061893602
Exit facility code: 1306
Exit error code: 30
Exit message: The patch installer has failed to update the following instance: MSSQLSERVER. To determine the reason for failure, review the log files.
Start time: 2014-08-14 01:34:48
End time: 2014-08-14 01:49:10
Requested action: Patch
Detail log file had the following listed:
2014-08-14 01:38:21 Slp: Attempting to run patch request for instance: MSSQLSERVER
2014-08-14 01:42:10 Slp: Error: Failed to run patch request for instance: MSSQLSERVER (exit code: -2061893602)
We also get the following error on screen:
The process cannot access the file ‘C:\Windows\SysWOW64\perf-MSSQL10_50.MSSQLSERVER-sqlagtctr.dll’ because it is being used by another process.
We get two options to retry or Exit (if I remember correctly). Retries fail anyhow and we have to exit. I do not have the screenshot for this.
The important thing is that version number changes to the SP or CU just failed.
First time, I tried a restart but that did not help. Then I ran ‘tasklist /m perf-MSSQL10_50. MSSQLSERVER-sqlagtctr.dll’ to find process/service that has a lock on the file, find the process/service and stop or kill it from Task Manager or Services.msc.
Within next couple of days I faced this on another cluster and that is when I started digging deeper and found that this is a bug.
1) Stop any custom performance monitor logs (Data Collector Sets) in Perfmon if running.
2) Stop Windows Management Instrumentation (WMI) Service (and any services which depend on it).
3) Start the installation again.
4) Restart the node after patching for services and process to get a normal start as usual.
1) Find the files which show up as ‘In Use’ and rename them to something else e.g. perf-MSSQL10_50.MSSQLSERVER-sqlagtctr_OLD.dll and then retry.
2) If you have multiple instances you may get same file in different folders for each instance.
3) You may get the similar ‘In Use’ error for another file SQAGTRES.DLL. Need to follow the same process of renaming them too and retry the update.
4) A newer version of the file will be created after the update is complete.