2

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

Karam Najjar
  • 527
  • 5
  • 21

3 Answers3

1

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.

CathalMF
  • 9,705
  • 6
  • 70
  • 106
0

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);

Original answer

Community
  • 1
  • 1
Rodrigo Silva
  • 432
  • 1
  • 6
  • 18
0

Also, you might want to find out if another program has it open (Excel or something)

Process Explorer can help with this:

http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

Thomas Taylor
  • 555
  • 4
  • 12