Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing Path for access database

I have a C# project which uses a database and currently the database is not embedded in the exe or C# project. I use the following path:

connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Anant\Documents\WebsiteSearch.accdb;
                                            Persist Security Info=False;";

Is there any way I can just add the WebsiteSearch.accdb into the project and change the path accordingly. The idea is when someone starts the exe on some other computer I don't want always to change the path of the database.

like image 959
Nant Avatar asked Oct 14 '25 16:10

Nant


1 Answers

For this usually we put the database in the application folder itself. If you put the db in the bin/debug than it would be always easy to access the DB

your code will turn like this

connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=WebsiteSearch.accdb;
Persist Security Info=False;";

Or alternatively,

connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source="+AppDomain.CurrentDomain.BaseDirectory+"WebsiteSearch.accdb;
Persist Security Info=False;";
like image 125
Mohit S Avatar answered Oct 17 '25 05:10

Mohit S