Sign in to follow this  
Skibula

[.net] my application will run on 2 pc and "server" c# winforms BUT..

Recommended Posts

hey all, first i need to say that im talking about C# WINFORMS .NET my question is like that: lets say i got "super" application that i made that only thing it does it to write into file that locate on a MAP DRIVE lets say G:so i have some pc that MAPPED G:\ (it located on a server ) so the only thing my app does it to write into a file (that already exist) lets say it write "HELLO WORLD" (it doesnt really matter ) --- so when the user run my app and click on the button SUBMIT it write into the file G:\MYFILE.TXT the string "HELLO WORLD" both pcs have the same G (well thats the point of map drive lol) -- MY QUESTION!!! what will happen when 2 pcs that have the same G:\ (both mapped) will run my app and will click SUBMIT on the same time? i guess i will get exception or something like that... how can i overcome this problem if there is a problem.. we all understand that its more then "hello world" and its more then 2 pc it just easyer for me to understand my problem like that thanks alot for every body that will try to help me or just gave some time to read my post

Share this post


Link to post
Share on other sites
A problem would arise if computer 2 tried to open the file for writing whilst before computer 1 had finished and closed the file. You could always force the problem by trying it on a single machine:

// Open the file for writing.
using (var File1 = File.OpenWrite(@"G:\MYFILE.TXT")) {
// Now try and open it again before closing it:
using (var File2 = File.OpenWrite(@"G:\MYFILE.TXT")) {
// ?
}
}


Result: IOException, The process cannot access the file 'G:\MYFILE.TXT' because it is being used by another process.

It would probably be easiest to attempt to handle the IOException and retry a number of times; alternatively, insert into a database (or similar) rather than straight file I/O. I'm not really sure, I've always used a database for this sort of application.

Share this post


Link to post
Share on other sites
This is the reason we have databases. The other option is an application running on a "server", that has the exclusive write permission on the file, the other applications, send their "requests" to change the file.

theTroll

Share this post


Link to post
Share on other sites
Well i want to make my database from excel file

but i have no idea how to do that..

i had another post that i have asked how to write into excel file

any idea?
or a guide or something that can help me out

Share this post


Link to post
Share on other sites
Visual Studio Express should have installed (or at least given you the option to install) Microsoft SQL Server Express - you could take a look at that.

If you wanted to stick with Office, there's always Access, but Excel is a spreadsheet application, not a database (contrary to what a lot of people seem to think). [wink]

Share this post


Link to post
Share on other sites
Another way (if you want to stick to Excel) is as follows:
1. Have the client apps create a file in the mapped folder. Make sure each client creates and writes to their own file.
2. Create a program that runs on the computer with the mapped drive that monitors for incoming/new files in the mapped drive (FileSystemWatcher)
3. Let this program process (pick up the file, read it and insert its data into the excel file) the client files, one by one.

Voila, you just created your own database system.

BTW: to make it more robust
- let each client create the file locally, fill it, and then in one move, move it to the mapped drive.
- let the server program delete(or rather move to an archive folder) processed files.

Share this post


Link to post
Share on other sites
i havnt been here for a while

i just wanted to say every body thanks for the help..

i figure it out and made me an sql database.

my program now run and all good :-)

i have few more questions but i will make new posts for that

thanks every body

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this