Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 17th, 2007, 05:14 PM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Simultaneous file write

I have a small website where members enter information and it is saved. The number of users isn't large (typically <50), so I use a simple text file to store the data. Users can modify their information, so I have the "open file, read all data, close file, modify data, create file, write file" logic. Everything works fine, or so I think.

Since multiple users can access the site "simultaneously", does the CreateTextFile method or Write method serialize requests? Or if UserA and UserB click "Save" at the same time, will one of the saves be lost? I can't find in any text the answer to this question.

I could use a database to solve this, but it seemed to be a bit of overkill. However, if that is the only way to solve this, that's what I'll implement next.

Thanks for any help/suggestions!

Jeff


Reply With Quote
  #2 (permalink)  
Old May 17th, 2007, 05:38 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Depends. Ideally, you will get an I/O error because there *should* be a lock on the file when userA opens the file for writing and that lock is then released when the write is finished. (You can see this effect when you open a file in code and fail to close your connection to it)

Personally, the thought of a "flat file" for data storage sends a chill up and down my spine! I like data, I like my data in a structured way with relationships so on and so forth BUT your problem is not simply solved by throwing a database behind your app.

Here is why. (Since I do not exactly what your users are doing, this is a bit of assumption)

In the event of an INSERT, you have no problem since rows are just being added to a table the problem arises if you give your users the abiltiy to UPDATE information. If userA and userB access the same set of data at the same time and they both make changes to that data independant of one another and then they each hit submit at different times...ut oh?

If userA clicks update first, the data is changed in the database to reflect their changes then userB clicks update and userA's data is overwritten. Which data is accurate? How can you be sure?

This is surely something you need to be aware of when writing back and forth to databases, albeit, your post didn't explictly say you were allowing your users to change information.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #3 (permalink)  
Old May 18th, 2007, 02:39 PM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your quick reply, Doug. I really appreciate it!

I'll do a quick test to see what error is returned if the file is already open. I agree that there *should* be some sort of lock, but I haven't found any documentation along those lines.

I'm not a DB person by any stretch, which is why I didn't implement one in the first place, plus the fact that the site is not critical in any sense of the word - it's for a club. But, I think a DB would solve the problem because each user would have their own DB record, so userA and userB saving at the same time would impact 2 different DB records. I'm not going to worry about userA having two different sessions and simultaneously hitting save!

Maybe I'll dive into creating a DB as my next enhancement. :)

Thanks again,

Jeff

Reply With Quote
  #4 (permalink)  
Old May 25th, 2007, 04:30 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Have you got the code for creating txt files, as it would be useful for a project i am creating.
Cheers,
       Apocolypse


------------------------------------------------
Apocolypse2005
Always ready and waiting to be helped!
Reply With Quote
  #5 (permalink)  
Old May 25th, 2007, 04:41 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Surely you haven't researched this yourself; a simple google search should net you plenty of results on this trivial task.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
write to file angelboy C# 2005 4 March 25th, 2007 05:01 AM
write file abaso.jadhav01 ASP.NET 2.0 Basics 0 November 24th, 2006 06:15 PM
reading HTML from file -> write to file mikeuk Beginning PHP 4 July 21st, 2004 05:40 AM
Simultaneous multiple file download balamuralivenkat Classic ASP Basics 6 December 17th, 2003 11:37 PM
Simultaneous xml file access jim77002 XML 2 September 1st, 2003 03:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.