473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Releasing lock on a text file?

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
Feb 9 '07 #1
4 1422


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" <da****@nospam.comwrote in message
news:uP**************@TK2MSFTNGP02.phx.gbl...
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


Feb 9 '07 #2
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.
Feb 9 '07 #3
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" <da****@nospam.comwrote in message
news:eJ****************@TK2MSFTNGP04.phx.gbl...
>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.

Feb 11 '07 #4
On Feb 11, 10:37 pm, "Alvin Bruney [MVP]" <some guy without an email
addresswrote:
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" <dav...@nospam.comwrote in message

news:eJ****************@TK2MSFTNGP04.phx.gbl...
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 ke****@leadingway.com.tw

Best regards,

Kelvin Chang

Feb 12 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: McGeeky | last post by:
Are there any best practices on releasing updates of an ASP.Net application to a virtual directory in a production environment? E.g. is it okay to simply copy over changes to ASP.Net pages in to...
2
by: Oenone | last post by:
I've an ASP.NET 2.0 project into which various Plug-In DLLs can be installed. I'm running it in the ASP.NET Development Server. In order to load one of the PlugIn DLLs I'm using...
2
by: Bram Stolk | last post by:
Hello, I've implemented, in C, a function that does a lot of I/O, and thus can block for a long time. If I execute this function in my Python script, it does not relinquish the global...
1
by: John Wright | last post by:
During my program I load an exe file using reflection. My program loads the file using reflection, checks the assembly version and does an update if the network version is different from the local...
5
by: jeff.ranney | last post by:
Hi all. I wrote this C# code: lock(this) { / /write to a file }
6
by: Gina_Marano | last post by:
Hey All, I am using multiple child threads per main thread to download files. It sometimes appears as if the same file is being downloaded twice. I am using "lock". Am I using it correctly? Any...
6
by: Peted | last post by:
Hi wondering what is the best way to do this Need a user to click a button, that sends 3 or 4 string based commands via a TCP/ip socket link I can connect to the ip device no problems, am...
5
by: Jennifer.Berube | last post by:
What is it exactly that makes application.lock such a bad thing? I just need a better explanation or link to a resource desribing it's downfall.
2
by: WingSiu | last post by:
I am writing a Logging util for my ASP.NET application. I am facing mulit process problem. I developed a class LogFactory, and have a method called Get_Logger to create a FileLogger, which will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.