Hi.
I have a webservice method that receives an XmlNode. It then loads an
existing xml file into an XmlDocument, appends the new XmlNode to the
XmlDocument and saves it back to the xml file. But what if another user is
doing the same thing at the same time? I did a test and found out that the
file is not automatically locked. Which means that the second user
overwrites the changes the first user made. Any ideas on how I can prevent
this?
Thanks,
Shawn 5 1065
What happens is that the XML content is loaded entirely in memory and the
DOM is created. So normally there are no connections to the file, unlike
when you have a stream.
Have not tried this but what you might try doing is to manually open the
file using the FileStream class (you can specify locks using the FileShare
enumeration), then use that stream when you call the XmlDocument.Load.
"Shawn" <bo********@hotmail.com> wrote in message
news:40********@news.wineasy.se... Hi. I have a webservice method that receives an XmlNode. It then loads an existing xml file into an XmlDocument, appends the new XmlNode to the XmlDocument and saves it back to the xml file. But what if another user is doing the same thing at the same time? I did a test and found out that the file is not automatically locked. Which means that the second user overwrites the changes the first user made. Any ideas on how I can prevent this?
Thanks, Shawn
Thanks Peter, I think that will do the trick. One thing though. If the
file is closed by another FileStream, is there a way I can wait until the
file is no longer locked instead of just writing an error message to the
user? Something like this:
Do While file.isClosed
'Just waiting for the file to open
Loop
Thanks,
Shawn
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:OF**************@TK2MSFTNGP10.phx.gbl...
What happens is that the XML content is loaded entirely in memory and the
DOM is created. So normally there are no connections to the file, unlike
when you have a stream.
Have not tried this but what you might try doing is to manually open the
file using the FileStream class (you can specify locks using the FileShare
enumeration), then use that stream when you call the XmlDocument.Load.
"Shawn" <bo********@hotmail.com> wrote in message
news:40********@news.wineasy.se... Hi. I have a webservice method that receives an XmlNode. It then loads an existing xml file into an XmlDocument, appends the new XmlNode to the XmlDocument and saves it back to the xml file. But what if another user is doing the same thing at the same time? I did a test and found out that the file is not automatically locked. Which means that the second user overwrites the changes the first user made. Any ideas on how I can prevent this?
Thanks, Shawn
Now you get into more interesting architectural issues.
The simplest way might be a bruit force method in which you use the loop but
use a try...catch block so the exception does not bubble (I do not know how
to ask the OS if a file is locked).
Another way might be to look into using the Mutex class. You could wrap
access to the file so that a Mutex is always created when the file is
opened, then released when closed.
"Shawn" <bo********@hotmail.com> wrote in message
news:40********@news.wineasy.se... Thanks Peter, I think that will do the trick. One thing though. If the file is closed by another FileStream, is there a way I can wait until the file is no longer locked instead of just writing an error message to the user? Something like this: Do While file.isClosed 'Just waiting for the file to open Loop
Thanks, Shawn
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message news:OF**************@TK2MSFTNGP10.phx.gbl... What happens is that the XML content is loaded entirely in memory and the DOM is created. So normally there are no connections to the file, unlike when you have a stream.
Have not tried this but what you might try doing is to manually open the file using the FileStream class (you can specify locks using the FileShare enumeration), then use that stream when you call the XmlDocument.Load. "Shawn" <bo********@hotmail.com> wrote in message news:40********@news.wineasy.se... Hi. I have a webservice method that receives an XmlNode. It then loads an existing xml file into an XmlDocument, appends the new XmlNode to the XmlDocument and saves it back to the xml file. But what if another user
is doing the same thing at the same time? I did a test and found out that
the file is not automatically locked. Which means that the second user overwrites the changes the first user made. Any ideas on how I can
prevent this?
Thanks, Shawn
The problem I ran into when using Mutex is that in a shared hosting
environment, its use would throw a security exception. I could never really
get the hosting company to understand the problem. I am not even sure
anyone there understood the question--what needed to be set so as to allow
the use of Mutex. Mutex was not in their vocabulary.
Its use worked fine on my local setup, though. So if you have control over
the server, then I think Mutex is the way to go in restricting the use of
files while they are being updated.
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:em**************@TK2MSFTNGP11.phx.gbl... Now you get into more interesting architectural issues.
The simplest way might be a bruit force method in which you use the loop
but use a try...catch block so the exception does not bubble (I do not know
how to ask the OS if a file is locked).
Another way might be to look into using the Mutex class. You could wrap access to the file so that a Mutex is always created when the file is opened, then released when closed.
"Shawn" <bo********@hotmail.com> wrote in message news:40********@news.wineasy.se... Thanks Peter, I think that will do the trick. One thing though. If the file is closed by another FileStream, is there a way I can wait until
the file is no longer locked instead of just writing an error message to the user? Something like this: Do While file.isClosed 'Just waiting for the file to open Loop
Thanks, Shawn
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message news:OF**************@TK2MSFTNGP10.phx.gbl... What happens is that the XML content is loaded entirely in memory and
the DOM is created. So normally there are no connections to the file,
unlike when you have a stream.
Have not tried this but what you might try doing is to manually open the file using the FileStream class (you can specify locks using the
FileShare enumeration), then use that stream when you call the XmlDocument.Load. "Shawn" <bo********@hotmail.com> wrote in message news:40********@news.wineasy.se... Hi. I have a webservice method that receives an XmlNode. It then loads an existing xml file into an XmlDocument, appends the new XmlNode to the XmlDocument and saves it back to the xml file. But what if another
user is doing the same thing at the same time? I did a test and found out that the file is not automatically locked. Which means that the second user overwrites the changes the first user made. Any ideas on how I can prevent this?
Thanks, Shawn
I've tried looking into Mutex and how to use it to lock a file with VB.NET,
but I haven't found any examples. Could you show me to an example?
Thanks,
Shawn
"William LaMartin" <la******@tampabay.rr.com> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl... The problem I ran into when using Mutex is that in a shared hosting environment, its use would throw a security exception. I could never
really get the hosting company to understand the problem. I am not even sure anyone there understood the question--what needed to be set so as to allow the use of Mutex. Mutex was not in their vocabulary.
Its use worked fine on my local setup, though. So if you have control
over the server, then I think Mutex is the way to go in restricting the use of files while they are being updated.
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message news:em**************@TK2MSFTNGP11.phx.gbl... Now you get into more interesting architectural issues.
The simplest way might be a bruit force method in which you use the loop but use a try...catch block so the exception does not bubble (I do not know how to ask the OS if a file is locked).
Another way might be to look into using the Mutex class. You could wrap access to the file so that a Mutex is always created when the file is opened, then released when closed.
"Shawn" <bo********@hotmail.com> wrote in message news:40********@news.wineasy.se... Thanks Peter, I think that will do the trick. One thing though. If
the file is closed by another FileStream, is there a way I can wait until the file is no longer locked instead of just writing an error message to
the user? Something like this: Do While file.isClosed 'Just waiting for the file to open Loop
Thanks, Shawn
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message news:OF**************@TK2MSFTNGP10.phx.gbl... What happens is that the XML content is loaded entirely in memory and the DOM is created. So normally there are no connections to the file, unlike when you have a stream.
Have not tried this but what you might try doing is to manually open
the file using the FileStream class (you can specify locks using the FileShare enumeration), then use that stream when you call the XmlDocument.Load. "Shawn" <bo********@hotmail.com> wrote in message news:40********@news.wineasy.se... > Hi. > I have a webservice method that receives an XmlNode. It then loads
an > existing xml file into an XmlDocument, appends the new XmlNode to
the > XmlDocument and saves it back to the xml file. But what if another user is > doing the same thing at the same time? I did a test and found out
that the > file is not automatically locked. Which means that the second user > overwrites the changes the first user made. Any ideas on how I can prevent > this? > > Thanks, > Shawn > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Niklas Lagergren |
last post by:
Hi, I'll try to explain. I'm now using C# and I have an xmlfile that
contains users and information about them, this xmlfile can be read and
changed from many threads in my application, as many...
|
by: Bruce Pullen |
last post by:
DB2 v7.2 (FP7 - DB2 v7.1.0.68) on AIX 5.2.0.0.
We're seeing unexpected single row (then commit) insert locking
behaviour.
We're seeing Applications that already hold row-level W locks in...
|
by: Sunny |
last post by:
Hi,
I can not understend completely the lock statement.
Actally what is locked:
1. the part of the code between {...}
or
2. the object in lock()
In the docs is written:
for 1: The lock...
|
by: Nashat Wanly |
last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp
Don't Lock Type Objects!
Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad
Rico...
|
by: Steven S |
last post by:
I have a Web Service which reads a xml file.
If I place it in the same direcectory where source code is
how should I then read it without using physical directory adress like...
|
by: Raj |
last post by:
I created a refresh deferred MQT, and during full refresh there were 4
or 5 lock waits, all waiting on a 'S' lock on Internal Catalog Cache ?
Can some one explain how to prevent this from happening?
|
by: shenanwei |
last post by:
DB2 V8.2 on AIX, type II index is created.
I see this from deadlock event monitor.
5) Deadlocked Connection ...
Participant no.: 2
Lock wait start time: 09/18/2006 23:04:09.911774
.........
|
by: sreelucky |
last post by:
Reading xmlfile into a datalist or reapeter countrol specially in .net2003
and also how do we read it in .net2005
|
by: Samuel R. Neff |
last post by:
When is it appropriate to use "volatile" keyword? The docs simply
state:
"
The volatile modifier is usually used for a field that is accessed by
multiple threads without using the lock...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |