Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

Multi User File Open / Partial File Locking Winnt

Greetings,
I am trying to get my database project started. Since I am building the multi-user database application I have know the best solution for allowing 2 or more users to write to the file. Is there a windows nt function that can do so? also can i partially lock a section of the file?
Thank you.
0
misha051797
Asked:
misha051797
1 Solution
 
TheGrinchCommented:
You say "database project" but then talk only about files. Which is it? Considerations with a database are quite different from those with files.
0
 
jkrCommented:
Well, 'LockFile()' allows you to lock prtions of a file...
0
 
misha051797Author Commented:
TheGrinch,
Cood point. What I am trying to do is to allow multi user access to the file.
I do not want an application to lock file, so other users can't read/write to the file.
I guess there must be a simple solution to what I am trying to do. Right?
0
 
gugaCommented:
When you open file with help of CreateFile function(Win32 API) u need use flags FILE_SHARE_READ|FILE_SHARE_WRITE.
U can read this file wihout sharing violation error.

hFile=CreateFile("data.base",
                 GENERIC_READ|GENERIC_WRITE,
                 FILE_SHARE_READ|FILE_SHARE_WRITE,
                 NULL,
                 OPEN_EXISTING,
                 FLAG_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,
                 NULL);
but when somebody want to write into file LockFile() needed. This
is unique solution to avoid conflict.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now