Cold Fusion/sharing violation help: weird cffile error (sharing violation)

Posted on 2003-03-14
Medium Priority
Last Modified: 2013-12-24
I am executing a fairly big sql query followed by a few smaller queries and then spitting the result to a comma-delimited (.csv) file. I tweaked the query yesterday (as per the customer) and the query runs longer and I now get an error processing cffile. It says there is a sharing violation. I go ahead and open the incomplete csv file and each time there is a different number of records that make it to this file (sometimes 673 records, sometimes 663, sometimes 670, etc.., and a couple of times it has completly ran - all the way thru with no errors!).  and I know no one else is using this file. I delete the file and run my program again and I still get the same problem. any suggestions? any help would greatly be appreciative.
Question by:adecatur
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8137690
Try putting a cflock around the write command. If CF tries to access the file while it is still open for writing, there could be an error.

Expert Comment

ID: 8137714
Try enclosing your <cfquery> and <cffile> tags in a <cflock> e.g.
<cflock timeout="60" type="EXCLUSIVE">


This will insure that everthing happens single threaded, and also allows you to put a timeout, so that if things drag on for longer than expect, you don't tie up the server.

The downside is that your query, will in fact be tieing up the server for the period of your lock.  (I don't know if this is acceptable or not).  If you find this solves the problem, then you can play around with where you place the lock in order to minimize the portion of the code that is locked and the period that it is locked.


Accepted Solution

TallerMike earned 1000 total points
ID: 8137807
I'm assuming that you're currently looping through the results of query, and appending the results one line at a time?

The best method to solve this problem is to stop opening and closing the file. What you'll want to do is to create a variable, and append all the records to that variable, and THEN add the variable to the CSV file. Make sure you append a return charater between each row in your variable so when you finally write it to the file, it will not all be on the same line. I think it's Chr(10) or Chr(13).

Don't bother locking the query, this won't do anything. To lock a query, you need to tell SQL to lock it either though CFTRANSACTION or in your SQL statement itself. But your problem isn't with the SQL, it with the time the file is open I'm guessing.

I'm also not sure that putting the lock statements around the CFFILE satement really have any meaning either. I believe that CFLOCK only works for variables (like client,session and application).

Anyhow, by writing the results all at once rather than looping, it should be faster and the server will only lock the file once (this is done automatically when the file is opened).

Author Comment

ID: 8138825
What you suggested worked!  Thank you TallerMike.  

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question