Reputation: 29860
I want to be able to use a database Foo.accdb in my ASP.NET project. What is the best way to connect to it? I want to make sure the project can be ported to another computer and still work, so should I just put the database file inside the project folder (the same folder where Default.aspx is located)?
Do I need to import the database into Visual Studio somehow?
I just want to be able to use the OleDb family of classes to manipulate the data. If this is all you have to do, is the path inside Web.config relative to Web.config?
So my connection string would be like:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Foo.accdb;User Id=admin;Password=;
Upvotes: 1
Views: 10842
Reputation: 91472
Generally, people use the App_Data folder for this.
A fully worked example is here: http://msdn.microsoft.com/en-us/library/445z2s49(v=vs.80).aspx
The advantage of having it within the structure is that you can move site and data at once. However, if the site becomes compromised, the database may be available too (although by default the app will be configured not to serve ANY files from this folder). This is why many people choose to store it in a folder outside the web site.
Also note that Access isn't really a multi user database so you may experience issues if you intend multiple users to access the database at once.
Also, you can use an absolute path or a relative path to locate the access mdb in the connection string. Take a look at the code the Add Data Source step in the MSDN link generates.
Upvotes: 2