Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Releasing lock on a text file?

Reply
Thread Tools

Releasing lock on a text file?

 
 
David Veeneman
Guest
Posts: n/a
 
      02-09-2007
Is there any way to forcibly release a lock on a text file, so that it can
be deleted?

I am testing an order-processing site that saves transaction information in
a text file that it attaches to its merchant notification. In most cases, it
works fine, but occasionally a lock on the text file won't get released.
When the next transaction comes along and tries to write over the file, the
server throws an IO error, saying that the file is in use by another
application.

What I'd like to do is forcibly release the lock, so that the file can be
deleted. Is that the right way to go about it? If so, how do I do it? If
not, what would be the best approach? Thanks.

David Veeneman
Foresight Systems


 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      02-09-2007


You best bet is to write a good finally statement


Streamwriter sw = null;

try
{
//write to the file
Streamwriter sw = yada yada yada;
}
finally
{
if(null!=sw)
{
sw.Close();
}
}

Something like that.

the finally block runs whether an error happens or not.

If you're already doing that, then maybe give a little more detail.






"David Veeneman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there any way to forcibly release a lock on a text file, so that it can
> be deleted?
>
> I am testing an order-processing site that saves transaction information

in
> a text file that it attaches to its merchant notification. In most cases,

it
> works fine, but occasionally a lock on the text file won't get released.
> When the next transaction comes along and tries to write over the file,

the
> server throws an IO error, saying that the file is in use by another
> application.
>
> What I'd like to do is forcibly release the lock, so that the file can be
> deleted. Is that the right way to go about it? If so, how do I do it? If
> not, what would be the best approach? Thanks.
>
> David Veeneman
> Foresight Systems
>
>



 
Reply With Quote
 
 
 
 
David Veeneman
Guest
Posts: n/a
 
      02-09-2007
> You best bet is to write a good finally statement

Yeah, I've got that. But for some reason I've been unable to pin down, The
lock is still not getting released.


 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      02-11-2007
In those cases, i like to use wholockme utility or filemon from sysinternals
to see what actually holds the lock on the process. It may not be the
process you think it is. At least, it certainly doesn't help to confirm it.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


"David Veeneman" <(E-Mail Removed)> wrote in message
news:eJsdt%(E-Mail Removed)...
>> You best bet is to write a good finally statement

>
> Yeah, I've got that. But for some reason I've been unable to pin down, The
> lock is still not getting released.
>



 
Reply With Quote
 
kelvin@leadingway.com.tw
Guest
Posts: n/a
 
      02-12-2007
On Feb 11, 10:37 pm, "Alvin Bruney [MVP]" <some guy without an email
address> wrote:
> In those cases, i like to use wholockme utility or filemon from sysinternals
> to see what actually holds thelockon the process. It may not be the
> process you think it is. At least, it certainly doesn't help to confirm it.
>
> --
> Regards,
> Alvin Bruney
> ------------------------------------------------------
> Shameless author plug
> Excel Services for .NET is coming...
> OWC Black book on Amazon andwww.lulu.com/owc
> Professional VSTO 2005 - Wrox/Wiley
>
> "David Veeneman" <(E-Mail Removed)> wrote in message
>
> news:eJsdt%(E-Mail Removed)...
>
>
>
> >> You best bet is to write a good finally statement

>
> > Yeah, I've got that. But for some reason I've been unable to pin down, The
> >lockis still not getting released.- Hide quoted text -

>
> - Show quoted text -


Please send me your more inquiry or requirements to my e-mail address
to http://www.velocityreviews.com/forums/(E-Mail Removed)

Best regards,

Kelvin Chang

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read-Write Lock vs primitive Lock() k3xji Python 7 12-30-2008 10:19 PM
Application.Lock()/UnLock() or lock(Application) nano2k ASP .Net Web Services 2 08-09-2007 09:31 AM
releasing interpreter lock in custom code? Bram Stolk Python 2 05-11-2006 11:08 AM
Threading - Why Not Lock Objects Rather than lock the interpreter Fuzzyman Python 3 12-05-2003 10:43 PM
RE: Threading - Why Not Lock Objects Rather than lock theinterpreter Robert Brewer Python 0 12-05-2003 05:33 PM



Advertisments