The process cannot access the file

J

John

I get this error while reading my config file but it is only occasionally
and not all the time. I'm not sure why its happening. Does anyone know what
could be going wrong? Thanks.

[28/03/2006 14:52:06] The process cannot access the file 'C:\GCC Business
Layer\GCCBL.config' because it is being used by another process. - at
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize,
FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean
bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at GCCBL.CoolFusion.ReadConfig(String myValue)
**************************************************************************

My Code :

System.IO.FileStream fsReadXml = new System.IO.FileStream

(System.AppDomain.CurrentDomain.BaseDirectory + "GCCBL.config",
System.IO.FileMode.Open);


// Create an XmlTextReader to read the file.

System.Xml.XmlTextReader myXmlReader =

new System.Xml.XmlTextReader(fsReadXml);

// Read the XML document into the DataSet.

DataSet myDataSet = new DataSet();

myDataSet.ReadXml(myXmlReader);

// Close the XmlTextReader

myXmlReader.Close();

fsReadXml.Dispose();
 
J

Jim Hughes

Change

(System.AppDomain.CurrentDomain.BaseDirectory + "GCCBL.config",
System.IO.FileMode.Open);
to

(System.AppDomain.CurrentDomain.BaseDirectory + "GCCBL.config",
System.IO.FileMode.Open, System.IO.FileAccess.Read);

By default it is opening read/write exclusive use.

Jim Hughes
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top