Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a project PROJECT_A which contains mdf file database. In the solution of this project I added one new project - PROJECT_B.

My question is:Can I use .mdf file from PROJECT_A in PROJECT_B?


What I have tried:

tried google but not getting solution
Posted
Updated 24-Jul-19 10:04am
v2

Yes.
But ... since different projects within the same solution can generate different executables (they always generate different assemblies) it may be that these two will be accessing the DB at the same time. If that is the case, I'd strongly suggest using SQL Server or MySQL instead of directly accessing the MDF file. While you can do it, it's always given me some difficult and intermittent problems - a server based DB system is designed for that kind of thing.
 
Share this answer
 
Comments
Member 14519466 23-Jul-19 9:02am    
Hello OriginalGriff,

My client wants service database(.mdf). So I can not use SQL Server.
TheRealSteveJudge 23-Jul-19 9:15am    
You seem to have understood the question and gave a good advice. 5*
Member 14519466 23-Jul-19 9:29am    
okay
Maybe you did not enter the right search criteria.

I entered "mdf file open multiple applications"
and found
How to use same .mdf file among multiple applications ?[^]
 
Share this answer
 
v2
Comments
Member 14519466 23-Jul-19 8:14am    
Hello Steve,

Maybe you did not enter the right search criteria also.
It is not my solution that i am looking for
TheRealSteveJudge 23-Jul-19 8:35am    
Hi,
then I would like to apologise.
Your problem looked to me very similar to the one described in the link.
Best regards,
Stephan
Member 14519466 23-Jul-19 8:40am    
Oh, It's Okay Stephan don't mind!
Yes. If more than one of the apps will be writing to the database, simply add a TIMESTAMP column to the affected table(s) to help mitigate the possiblility of contention between apps.
 
Share this answer
 
It is possible, and yes you can do that. .mdb is simply a file. And access engine (assuming it to access db) will tell if a connection cannot be made (due to too many users) and therefore manages the concurrency. I have interacted with .mdb file on a multithreading environment where two processes can use the same file. In that scenario, I was checking if the file is open, then use the opened instance which will be slightly different in your case if the project A and project B are in different machines and then you are dealing with network shared resource and there could be connectivity related issues.
 
Share this answer
 
Comments
Member 14519466 24-Jul-19 23:22pm    
Porject A and Project B are in same machine
Benktesh Sharma 25-Jul-19 10:31am    
That is even easier. Another suggestion is to make a third project (a dll) that only does the database reading and writing and refer to that dll from both projects. This way you can scale the mdb to something else and individual projects won't need to worry about the data access. Lets say the dll has class ProcessData with member functions to do read/write. Then both project can refer to the dll and file read/write can be handled at one place.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900