ASP database connection code
'Solved the ACCESS database path problem!
'Use DBType = 0 or DBType = 1 to distinguish between the AC database and the MSSQL database.
'The precautions for using the AC library are described in the program.
--------------------------------------------------------------------------------
Dim DBType, Conn, StrConn
DBType = 0' 0 indicates the Access database, and 1 indicates the MSSQL database.
If (DBType = 0) Then
***** ********************************
Dim DbFolderName, DbFolder_Path, SiteFolder
DbFolderName = "ArticleData" 'name of the folder where the database is located
DbFolder_Path = Server. MapPath (DbFolderName) 'database path
SiteFolder = "Article" 'name of the root directory of the system
If Session ("RootDir") = "" Then
Session ("RootDir") = Mid (DbFolder_Path, 1, InStr (1, DbFolder_Path, SiteFolder, 1)-1) & SiteFolder
End if
Set Conn = Server. CreateObject ("Adodb. Connection ")
StrConn = "Driver = {Microsoft Access Driver (*. mdb)}; DBQ = "& Session (" RootDir ") &" \ "& DbFolderName &" \ Data. mdb "'connect to the database
Conn. Open StrConn
'*************************************** **************************************** ***
ElseIf (DBType = 1) Then
******* ******************************
Dim DBUserID, DBPassWord, DBName, DBIP
'Modify the following information to suit your website
DBUserID = "sa" 'database Login Name
DBPassWord = "" 'Database Password
DBName = "dbname" 'Database Name
DBIP = "local" 'address of the database. If it is a local database, it is: (local)
Set Conn = Server. CreateObject ("Adodb. Connection ")
StrConn = "PROVIDER = SQLOLEDB.1; Data Source =" & DBIP & "; Initial Catalog =" & DBName & "; Persist Security Info = True; User ID =" & DBUserID &"; password = "& DBPassWord &"; Connect Timeout = 30"
Conn. Open StrConn
'*************************************** **************************************** ***
Else
************* ************************************
Response. Write "database setup error. Please contact the administrator! "
Response. End
End If
'Response. Write StrConn