ASP connection database of the almighty Code

Source: Internet
Author: User
Tags connect mssql mssql server access database root directory
Connection database ' solves the problem of Access database path!
' Use dbtype=0 or dbtype=1 to differentiate between the AC library and the MSSQL Library
"The specific use of the AC library should pay attention to matters, please see the program description

--------------------------------------------------------------------------------
Dim Dbtype,conn,strconn
Dbtype=0 ' 0 is an Access database, and 1 is a MSSQL database

If (dbtype=0) Then
' ********************************access database *************************************
Dim Dbfoldername,dbfolder_path,sitefolder
Dbfoldername= folder name of "Articledata" database
Dbfolder_path = Server.MapPath (dbfoldername) ' The path to the database
Sitefolder= name of the root directory where the "Article" system resides

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)};D bq=" & Session ("RootDir") & "\ & Dbfoldername &" \dat A.mdb "' Connect to Database
Conn.Open strconn
'**********************************************************************************
ElseIf (dbtype=1) Then
' *****************************mssql Server database *************************************
Dim Dbuserid,dbpassword,dbname,dbip
' Modify the following information to suit your site
dbuserid= "sa" ' Database login name
dbpassword= "" ' Database password
Dbname= "dbname" database name
Dbip= the address of the "local" database and, if it is a native database:

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
' *********************** Database Setup Error *************************************************
Response.Write "Database Setup error, please contact admin!" "
Response.End
End If
' Response.Write strconn




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.