Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFFILE Error

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I use CFFILE to create temporary Excel template files, the error message I receive is this:

<<
Error processing CFFILE Error attempting to write data to target file 'd:\Inetpub\Error: There was a sharing violation.

The error occurred while processing an element with a general identifier of (CFFILE), occupying document position (277:1) to (277:84).
>>

The filename is built dynamically, and the number following IQY= is a randomly generated number between 1 and 1000 to ensure that if two or more users try to use the application at the same time there is no filename duplication. Beyond that, I also use a CFLOOP routine before the <CFFILE> tag writes the contents of the file to check and see if a file with an identical name exists, if it does it adds a 1 to the filename before the file extension and checks again until it finds a filename that does not exist on the server. This Tag works 99% of the time and I can't figure out why I get this error from time to time. I can't see how it would be trying to overwrite an open file if it checks for a unique filename before writing, the directory has plenty of space, and all the permissions it needs (otherwise it wouldn't EVER work). Any thoughts?

SnoBoredCa
 
Hey SnoBored,

I would use a <cflock> tag around the code to ensure the create section is run single threaded. If the code that creates the filename (including the <cfloop> part) is inside the <cflock> there should be absolutely no way of creating duplicate file names. The method you describe should under normal circumstances never create a conflict but the possibility does exist. If two people click the link at the same time, it's possible to have two separate file names created that match and have the &quot;file exists&quot; return false in both cases if the timing is correct. Using <cflock> though would eliminate this very improbable case.

Since random numbers are not randomly generated but are preset numbers retrieved from a list that's been &quot;seeded&quot;, it's possible that two threads executing at the same time could receive the same random numbers. The timing would have to be such that thread 1 gets a random number and before the random number index is moved, thread 2 requests a random number and gets the same number. If this is possible, then it would make your error much more probable under light user loads. Otherwise, I would think you would have to have a very heavy traffic load before the odds of it happenning become great enough to see that error.

Hope this helps,
GJ
 
<cflock name=#fileout# timeout=15 type=&quot;exclusive&quot;>
<cfinclude template=&quot;../../filecheck.cfm&quot;>
<cffile action=&quot;write&quot; output=&quot;#txtout#&quot; file=&quot;#fileout#&quot;>
</cflock>

like that? or should the random number generation be within the <CFLOCK> as well? The 'filecheck.cfm' page is only to see if the file exists and change the filename if it does. I think this is going to work, however I thought I'd get your opinion.

SnoBoredCa
 
I think you're right in that having the filecheck inside the <cflock> will probably be sufficient but I would go ahead and put alll code relating to the file name creation inside it. I would also change the name of the lock to a static string as my gut feeling is that there might be a way for this to fail if you use a dynamic lock.

GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top