Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Delete File

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2011-09-21 : 05:37:38
Hi,

Am trying to delete a file in a folder but receive the error..

Error Deleting File or Folder

Cannot delete XXX: It is being used by another person or program
Close any programs that might be using the file and try again.


I have tried few times but still I have the same problem. I know why it is happening but I dont know how to stop it.

A job was executed which worked on the folder with the file, but the application failed. Now, it is still remembering the run and hence thinks it is still in use.

How can I stop this and delete the file..

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-21 : 05:39:46
Is this a sql job? if yes connect to respective server in management studio and check if job process is still active by running sp_who2.If active stop job using KILL command and then try deletion.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2011-09-21 : 05:46:14
so I saw the sys.sp_who2 in the Master database when I right click it says Modify / Refresh - therefore I selected Modify and Execute- Received an error Invalid object name 'sys.sp_who2'.

And how will I kill the process? Whats the command

Thank you so much
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-21 : 05:57:47
first run sp_who2 active and see processes listed to identify process application uses

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2011-09-21 : 06:06:47
I found the processes - and read somewhere in the internet which says the first 50 results are system SPIDs, and they do not effect slowdowns on the system. Now I have the following SPIDs from 51

SPID status Login DBName Command CPUTime DiskIO ProgramName
51 sleeping NT AUTHOURITY\SYSTEM msdb Awaiting Command 0 0 SQLAGENT90-id<4740>
52 sleeping NT AUTHOURITY|SYSTEM msdb Awaiting Command 0 8 SQLAgent - Generic Refresher
53 sleeping sa master Awaiting Command 500 1829 Microsoft SQL Server Management Studio
54 sleeping sa master Awaiting Command 31 0 Microsoft SQL Server Management Studio
55 RUNNABLE sa master SELECT INTO 15 1 Microsoft SQL Server Management Studio

Please could you enlight me which process is holding the deletion. I reckon its 51 & 52 ... If so how can I kill them ?

Thank you
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-21 : 06:15:19
they both are sql agent jobs. run this and see what command they're executing

dbcc inputbuffer(51)

dbcc inputbuffer(52)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2011-09-21 : 06:22:31
OMG - I hope this is NOT BAD

I went to management - Activity Monitor - View Processes - On the Process Info - I kill all the Processes from 51 - 54.

Tried to delete the file no success..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-21 : 06:33:00
is application running in same machine or different server?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2011-09-21 : 06:38:38
its running on the same machine and server - although it updates a database in another server too
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-21 : 06:41:26
try restarting server and then check if file can be deleted

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -