指引网

当前位置: 主页 > 编程开发 > ASP >

万能的数据库连接程序

来源:网络 作者:佚名 点击: 时间:2017-06-22 20:19
[摘要] 我从来就不用DNS连接,我觉得那个很不方便,下面这部分程序可说是万能的数据库连接程序几乎可以连接所有的MS数据库,自己拿去研究吧(这个程序是“ASP网页制作教程”这本书里面
我从来就不用DNS连接,我觉得那个很不方便,下面这部分程序可说是万能的数据库连接程序几乎可以连接所有的MS数据库,自己拿去研究吧(这个程序是“ASP网页制作教程”这本书里面的——一本好书):
<%
'---------------------------------------------------
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 )
------分隔线----------------------------