Hi everyone - I have a problem when I first try to create an xml file and write to it. If the file doesn't exist, I create the xml file, then I write to it using a dataset. The problem is, if the file doesn't exist, I create the file then when I try to write to it, an exception is thrown saying the File is in use by another process. Any subsequent tries, after the first try, work perfectly. I can't figure out what is happening. Can anyone help? Here is the code block that fails:
I'd really like an answer to what is wrong and a possible solution. But if there is an alternative way of doing this, I'd like to know that as well. But learning the problem is best.
Thanks,
Mike
Code:
' strFullPath is the path to the xml file
fi = new FileInfo(strFullPath)
if fi.Exists AND fi.Extension.Equals(".xml") then
trace.write("File exists and is of type xml")
else
fi.Create()
trace.write("Creating file")
end if
trace.write("Connecting to db")
createSQLConnection 'call to create a connection
sqlDA = new SqlDataAdapter(strSQLStatement, myConn)
sqlDA.Fill(dsDBData, "reservation")
' both lines below don't work...this is where it goes bad
' dsDBData.WriteXml(strFullPath,XmlWriteMode.IgnoreSchema)
dsDBData.WriteXml(strFullPath)
I'd really like an answer to what is wrong and a possible solution. But if there is an alternative way of doing this, I'd like to know that as well. But learning the problem is best.
Thanks,
Mike