Releasing lock on a text file?

Discussion in 'ASP .Net' started by David Veeneman, Feb 9, 2007.

  1. 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
     
    David Veeneman, Feb 9, 2007
    #1
    1. Advertising

  2. David Veeneman

    sloan Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
     
    sloan, Feb 9, 2007
    #2
    1. Advertising

  3. > 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.
     
    David Veeneman, Feb 9, 2007
    #3
  4. 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" <> wrote in message
    news:eJsdt%...
    >> 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.
    >
     
    Alvin Bruney [MVP], Feb 11, 2007
    #4
  5. David Veeneman

    Guest

    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" <> wrote in message
    >
    > news:eJsdt%...
    >
    >
    >
    > >> 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

    Best regards,

    Kelvin Chang
     
    , Feb 12, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fuzzyman
    Replies:
    3
    Views:
    532
    Andrew MacIntyre
    Dec 5, 2003
  2. Robert Brewer
    Replies:
    0
    Views:
    520
    Robert Brewer
    Dec 5, 2003
  3. Bram Stolk
    Replies:
    2
    Views:
    290
    Sion Arrowsmith
    May 11, 2006
  4. k3xji
    Replies:
    7
    Views:
    879
    Gabriel Genellina
    Dec 30, 2008
  5. nano2k

    Application.Lock()/UnLock() or lock(Application)

    nano2k, Jul 23, 2007, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    316
    nano2k
    Aug 9, 2007
Loading...

Share This Page