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.
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;";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With