ASP database connection code

Source: Internet
Author: User

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

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.