How to send a database that is being used by another process to email c#
In my program I am sending a database in the form_closed event to my email , in in form_loadevent I want to get the database from my email and to use it . I'm doing this to get the database from another computers in my project.
but the problem is in this line :
Attachment database = new Attachment("DataBase\\USBrowser.accdb");
I get an exception that the database is being used by another process , how to deal with this problem ? can I stop the database of being used by another process? ,, any other suggestions are welcomed .
thanx in advance
If the issue is:
How to read a file being used by another process?
Then you can access it in "read mode":
Stream stream = File.Open("DataBase\\USBrowser.accdb", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); StreamReader streamReader = new StreamReader(stream);
If your program is using the database then you will need to stop the database before using it.
You might also be able to make a copy of the database before attempting to add it as an attachment and then add the copy.
Also, you might want to find out if another program has it open (Excel or something)
Process Explorer can help with this: