Solutions for Path Problems in ASP files and connecting files using a single database

Source: Internet
Author: User
Tags servervariables

Don't talk about anything, just give it to the original Code Copy code The Code is as follows: '========================================================== ==============================
'1. The name of the folder where the website is located cannot be "root"
2. The name of the folder where the website is located. Duplicate folder names are not allowed in the physical path, for example, F: \ t. T is the name of the folder where the website is located. An error occurs.
'================================================ ======================================
Dim dbpath, dbname, DB, connstr, websitefoldername
On Error resume next

Websitefoldername = "weldsitebuilder"
Dbpath = "_ sitedata \" 'note that it is a backslash and only
Dbname = "acteedata. mdb" 'Database Name
DB = getsitephysicalpath (websitefoldername) & dbpath & dbname
'Response. Write ("physical path of the current database:" & server. mappath (db ))
'Response. Write ("<HR> ")
'Response. Write ("Path of the page accessed by the current request:" & request. servervariables ("url "))
'Response. Write ("<HR> ")
'Response. Write ("root path of the current site:" & request. servervariables ("appl_physical_path "))
'Response. Write ("<HR> ")
'Response. Write ("current site path status:" & request. servervariables ("appl_md_path "))
'Response. Write (db)
'Response. End ()
'====================================
Set conn = server. Createobject ("ADODB. Connection ")
Connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & DB
Conn. Open connstr
If err then
Err. Clear
Set conn = nothing
Response. Write "database connection error! "
Response. End
End if

Sub closeconn ()
Conn. Close
Set conn = nothing
End sub

'obtain the absolute path of the website directory (with the "\" Number)
function getsitephysicalpath (wsfn)
dim appl_md_path, appl_md_patharray, path, wspp
wspp = request. servervariables ("appl_physical_path") 'runs under the root directory by default.

Appl_md_path = request. servervariables ("appl_md_path ")
Appl_md_patharray = Split (appl_md_path ,"/")
Path = appl_md_patharray (ubound (appl_md_patharray ))
If ucase (PATH) = "root" then 'determines whether the website is in an independent application.ProgramRun
'Then determine if the website is running in a folder
If instr (wspp, wsfn) = 0 then 'the website runs in a folder under the root directory
'Based on the address of the accessed page, spell out the address of the folder where the website is located
Dim currenturl, namearray
Currenturl = request. servervariables ("url ")
Namearray = Split (currenturl ,"/")
For I = lbound (namearray) to ubound (namearray)
If ucase (namearray (I) = ucase (wsfn) then
For J = 0 to I
Wspp = wspp + namearray (j) + "\"
Next
Exit
End if
Next
Else' indicates that the website is running in the root directory
'You don't have to do anything. The returned value has been initialized.
End if
Else' indicates that the website is running in a virtual directory
'Do nothing. The returned value has been initialized.
End if
Wspp = Replace (wspp ,"\\","\")
Getsitephysicalpath = wspp
End Function

PS: The above is only for the Access database to solve the problem of wrong inclusion path, so that the site can share a database connection file, any file contains it, the database can be opened normally, you don't have to worry about how the website runs (running under the root directory, running under the virtual path, and running under the root directory + directory where the website is located ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.