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

Answers


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


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:

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


Need Your Help

How can I define a heuristic function for water jug?

algorithm search artificial-intelligence a-star heuristics

I am trying to put a water jug problem into a heuristic function but I am finding some problems.

Python append() vs. + operator on lists, why do these give different results?

python list append nested-lists

Why do these two operations (append() resp. +) give different results?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.