简体   繁体   中英

access resources inside the App_Data in asp.net

I have an asp.net application which have the following structure:

App_code
App_Data
   data.mdb
js
css
manager
  App_Data
  App_Code
  web.config
.....

Now I want to access the data.mdb in manager/web.config .

How to access it?


I tried this:

<add key="connstr" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|datadirectory|\data.mdb" />

Then I got the error:

'manager/data.mdb' does not exist.

Then I tried this: Data Source=|datadirectory|\\..\\App_Data\\data.mdb .

I got error: connstr not valid.

You need to access the one in manager/ . I hope then there's one way to do this. You can try giving the complete or absolute address of the database file data.mdb . I mean if you are working on a local system, it should be the exact address on you harddrive like C:/Folder/YourProject/Manager/data.mdb and if you need to work on a web server, just add the exact address of your hosting, which can be taken from the hosting panel itself or else there's another way.

What you can do is just create a temp.aspx file and in the temp.aspx.cs (I am assuming it to be C# for code behind) you can print the server's path like:

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(Server.MapPath("~").ToString());
} 

and upload it on your hosting in the root. When you access it, you'll get the absolute address of the hosting. And what you need to do now is just copy and paste the address in the connectionString of web.config while appending your DB path and you'll get the application working. And remember to remove the temp.aspx from the hosting.

So if your address is like D:/Hosting/4232322/Some_directory

Your complete string should be like this:

<add name="connstr" providerName="Microsoft.Jet.OleDB.4.0" connectionString="Provider=Microsoft.Jet.OleDB.4.0; Data Source=D:/Hosting/4232322/Some_directory/manager/data.mdb; Persist Security Info=True;"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM