The relative path of ASP. NET to access the database. How to use the relative path in Web. config and call this relative path in the class file (Source code)?
I am using VS 2005. After debugging, how can I implement it,CodeAs follows:
First, add the following code to the <etettings> node of the web. config file:
<! -- Data source -->
<Add key = "myds" value = "provider = Microsoft. Jet. oledb.4.0; Data Source ="/>
<! -- Database relative path -->
<Add key = "myconn" value = "app_data \ database. mdb"/>
Then, write a class file and call the above definition. The Code is as follows:
'The difficulty lies in defining a connection string. Many servers are used online. mappath, but it still does not work. Note that the request is used here. mappath (this is useless to ASP)
Public connstr as string = configurationsettings. receivettings ("myds") + httpcontext. Current. Request. mappath ("~ ") + (Configurationsettings. receivettings (" myconn "). Trim ())
There is also a better method: this is a new feature of Asp.net 2.0, using | datadirectory |
In the Web. config file:
<Add name = "connstr" connectionstring = "provider = Microsoft. jet. oledb.4.0; Data Source = | datadirectory | \ dB. mdb "providername =" system. data. oledb "/>
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/yydy1983/archive/2007/07/19/1698536.aspx