A Universal Database connection program

Source: Internet
Author: User
Program | data | database | Database connection I've never used a DNS connection. I think that is very inconvenient, the following part of the program can be said to be a universal database connection program can almost connect all the MS database, you take to study it (this program is "ASP Web page Production tutorial" In this book-a good book):
<%
'---------------------------------------------------
Function getmdbconnection (FileName)
Dim Provider, DBPath Provider = "provider=microsoft.jet.oledb.4.0;"
DBPath = "Data source=" & Server.MapPath (FileName)
Set getmdbconnection = getconnection (Provider & DBPath)
End Function '---------------------------------------------------
Function getsecuredmdbconnection (FileName, Password)
Dim Provider, DBPath Provider = "provider=microsoft.jet.oledb.4.0;"
DBPath = "Data source=" & Server.MapPath (FileName)
Set getsecuredmdbconnection = getconnection (Provider & DBPath &); Jet oledb:database password= "& Password)
End Function '---------------------------------------------------
Function getdbcconnection (FileName)
Dim Driver, sourcetype, DBPath Driver = "Driver={microsoft Visual FoxPro Driver};"
SourceType = "SOURCETYPE=DBC;"
DBPath = "sourcedb=" & Server.MapPath (FileName)
Set getdbcconnection = getconnection (Driver & sourcetype & DBPath)
End Function '---------------------------------------------------
Function getdbfconnection (Directory)
Dim Driver, sourcetype, DBPath Driver = "Driver={microsoft Visual FoxPro Driver};"
SourceType = "SOURCETYPE=DBF;"
DBPath = "sourcedb=" & Server.MapPath (Directory)
Set getdbfconnection = getconnection (Driver & sourcetype & DBPath)
End Function '---------------------------------------------------
Function getexcelconnection (FileName)
Dim Driver, DBPath Driver = "Driver={microsoft Excel Driver (*.xls)};"
DBPath = "dbq=" & Server.MapPath (FileName)
Set getexcelconnection = getconnection (Driver & "readonly=0;" & DBPath)
End Function '---------------------------------------------------
Function gettextconnection (Directory)
Dim Driver, DBPath Driver = "Driver={microsoft Text Driver (*.txt; *.csv)}; "
DBPath = "dbq=" & Server.MapPath (Directory)
Set gettextconnection = getconnection (Driver & DBPath)
End Function '---------------------------------------------------
Function getsqlserverconnection (Computer, UserID, Password, Db)
Dim Params, conn Set getsqlserverconnection = Nothing
Params = "Provider=SQLOLEDB.1"
Params = Params & ";D ata source=" & Computer
Params = Params & "; User id= "& UserID
Params = Params & "; Password= "& Password
Params = Params & "; Initial catalog=" & Db
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open Params
Set getsqlserverconnection = conn
End Function '---------------------------------------------------
Function Getmdbrecordset (FileName, Source)
Set Getmdbrecordset = Getmdbrs (FileName, Source, 2, "")
End Function '---------------------------------------------------
Function Getmdbstaticrecordset (FileName, Source)
Set Getmdbstaticrecordset = Getmdbrs (FileName, Source, 3, "")
End Function '---------------------------------------------------
Function Getsecuredmdbrecordset (FileName, Source, Password)
Set Getsecuredmdbrecordset = Getmdbrs (FileName, Source, 2, Password)
End Function '---------------------------------------------------
Function Getsecuredmdbstaticrecordset (FileName, Source, Password)
Set Getsecuredmdbstaticrecordset = Getmdbrs (FileName, Source, 3, Password)
End Function '---------------------------------------------------
Function Getdbfrecordset (Directory, SQL)
Set Getdbfrecordset = Getotherrs ("DBF", Directory, SQL, 2)
End Function '---------------------------------------------------
Function Getdbfstaticrecordset (Directory, SQL)
Set Getdbfstaticrecordset = Getotherrs ("DBF", Directory, SQL, 3)
End Function '---------------------------------------------------
Function Getdbcrecordset (FileName, SQL)
Set Getdbcrecordset = Getotherrs ("DBC", FileName, SQL, 2)
End Function '---------------------------------------------------
Function Getdbcstaticrecordset (FileName, SQL)
Set Getdbcstaticrecordset = Getotherrs ("DBC", FileName, SQL, 3)
End Function '---------------------------------------------------
Function Getexcelrecordset (FileName, SQL)



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.