ASP database connection five methods

第一种 - 这种方法用在ACCESS中最多
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" _
& Server.MapPath("aspfree.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn

第二种-这种方法用在SQL SERVER中多
strconn = "Driver={SQL Server};Description=sqldemo;SERVER=127.0.0.1;" _
&"UID=LoginID;Password=;DATABASE=Database_Name"
set conn = server.createobject("adodb.connection")
conn.open strconn

第三种
strconn="Driver={Microsoft Access Driver(*.mdb)};" _
&"DBQ=F:\Inetpub\wwwroot\somedir\db1.mdb;DefaultDir=" _
&"f:\Inetpub\wwwroot\somedir;uid=LoginID;" _
&"pwd=Password;DriverId=25;FIL=MSAccess;"
set conn = server.createobject("adodb.connection")
conn.open strconn


The fourth application system data source
at The following A uses the Name the Data Source: Example
the SET conn = server.createobject ( "ADODB.Connection")
conn.Open "Example"


The fifth use of ODBC data sources, provided that you have set up ODBC data source in the control panel of
the SET rs = server.createobject ( "ADODB.Recordset")
rs.open "tblname", "DSNName", 3, 3 first species - this method is most used in the ACCESS
strConn = "the DRIVER = the Microsoft Access Driver (* .mdb); DBQ =" _
& the Server.MapPath ( "aspfree.mdb")
SET Conn = Server.CreateObject ( "ADODB.Connection ")
conn.Open strConn

Here is a website to explain the database connection, very good
 Connectiong   :http://tempuri.org/tempuri.html

the ASP database connection codes versatile

'Solves the problem of ACCESS database path!
'Employs DBType = 0 or DBType = 1 AC to distinguish library or libraries MSSQL
' specific library using AC should be noted that matters, see procedure described

-----------------------------------------------
Dim DBType, conn, strConn
DBType 0 = '0 Access database, a database of MSSQL

IF (DBType = 0) the Then
'********************************************************* the ACCESS database ******************
Dim DbFolderName, DbFolder_Path, SiteFolder
DbFolderName = "ArticleData" 'database where the folder name
DbFolder_Path = Server.MapPath (DbFolderName)' path to the database where
SiteFolder = "Article" 'system where the root directory name

   The Session IF ( "the RootDir") = "" the Then
        the Session ( "the RootDir") = Mid (DbFolder_Path,. 1, the InStr (. 1, DbFolder_Path, SiteFolder,. 1) -1) & SiteFolder
   End IF
   the Set Conn = Server.CreateObject ( "Adodb .Connection ")
   strConn =" Driver = {the Microsoft Access Driver (* .mdb)}; DBQ = "& the Session (" the RootDir ") &" \ "& DbFolderName &" \ Data.mdb " 'is connected to a database
   Conn.Open strConn
'**************************** **
ElseIf (= DBType. 1) the Then
'******************************************************** MSSQL SERVER database ******
   Dim DBUserID, DBPassword, DBName, DBIP
   ' modified to fit the following information your website
   DBUserID = "sa" 'database login name
   DBPassWord = ""'Database Password
   DBName = "dbname" 'the name of the database
   where the address database DBIP = "local"', if it is compared with the local database: (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"数据库设置错误,请联系管理员!"
   Response.End
End If
'Response.Write StrConn

'Solves the problem of ACCESS database path!
'Employs DBType = 0 or DBType = 1 AC to distinguish library or libraries MSSQL
' specific library using AC should be noted that matters, see procedure described

-----------------------------------------------
Dim DBType, conn, strConn
DBType 0 = '0 Access database, a database of MSSQL

IF (DBType = 0) the Then
'********************************************************* the ACCESS database ******************
Dim DbFolderName, DbFolder_Path, SiteFolder
DbFolderName = "ArticleData" 'database where the folder name
DbFolder_Path = Server.MapPath (DbFolderName)' path to the database where
SiteFolder = "Article" 'system where the root directory name

   The Session IF ( "the RootDir") = "" the Then
        the Session ( "the RootDir") = Mid (DbFolder_Path,. 1, the InStr (. 1, DbFolder_Path, SiteFolder,. 1) -1) & SiteFolder
   End IF
   the Set Conn = Server.CreateObject ( "Adodb .Connection ")
   strConn =" Driver = {the Microsoft Access Driver (* .mdb)}; DBQ = "& the Session (" the RootDir ") &" \ "& DbFolderName &" \ Data.mdb " 'is connected to a database
   Conn.Open strConn
'**************************** **
ElseIf (= DBType. 1) the Then
'******************************************************** MSSQL SERVER database ******
   Dim DBUserID, DBPassword, DBName, DBIP
   ' modified to fit the following information your website
   DBUserID = "sa" 'database login name
   DBPassWord = ""'Database Password
   DBName = "dbname" 'the name of the database
   where the address database DBIP = "local"', if it is compared with the local database: (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"数据库设置错误,请联系管理员!"
   Response.End
End If
'Response.Write StrConn


Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2007/03/15/676397.html

Guess you like

Origin blog.csdn.net/weixin_34008784/article/details/93495906