通行证: 用户 密码 域名空间  下载中心 社区论坛 信息公告 my小屋
联系我们
设为首页
加入收藏

 

qq,asp,php,jsp,xml,sql,.net,编程 程序 网页图象 建站经验 私服
首页 | 新闻资讯 | 编程开发 | 网页设计 | 图形图象 | 网络媒体 | 网站模板 | 数 据 库 | 投稿
论坛 | 操作系统 | 系统优化 | 网络安全 | 黑客技术 | 硬件学堂 | 硬件报价 | 服 务 器 | 地图
专题 | 应用软件 | 聊天通讯 | q q 专栏 | 建站经验 | 在线工具 | 站长club | 注 册 表 | 旧版
社会 | 游戏娱乐 | 设计欣赏 | 疑难解答 | 社区论坛 | 网络赚钱 | 网站地图 | 广告服务 | 服务
当前位置:首页>>编程开发>>sql专区>>正文 新版上线![旧版]
注:打开慢时请稍等
万能的数据库连接程序

http://www.iyit.net  日期:2006-5-3 19:18:22  来源:  点击:
参加讨论】 我从来就不用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 )
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 & ";data 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 )
set getexcelrecordset = getotherrs( "excel", filename, sql, 2 )
end function

'---------------------------------------------------
function getexcelstaticrecordset( filename, sql )
set getexcelstaticrecordset = getotherrs( "excel", filename, sql, 3 )
end function

'---------------------------------------------------
function gettextrecordset( directory, sql )
set gettextrecordset = getotherrs( "text", directory, sql, 2 )
end function

'---------------------------------------------------
function gettextstaticrecordset( directory, sql )
set gettextstaticrecordset = getotherrs( "text", directory, sql, 3 )
end function

'---------------------------------------------------
function getsqlserverrecordset( conn, source )
dim rs

set rs = server.createobject("adodb.recordset")
rs.open source, conn, 2, 2
set getsqlserverrecordset = rs
end function

'---------------------------------------------------
function getsqlserverstaticrecordset( conn, source )
dim rs

set rs = server.createobject("adodb.recordset")
rs.open source, conn, 3, 2
set getsqlserverstaticrecordset = rs
end function

'---------------------------------------------------
function getconnection( param )
dim conn

on error resume next
set getconnection = nothing
set conn = server.createobject("adodb.connection")
if err.number <> 0 then exit function

conn.open param
if err.number <> 0 then exit function
set getconnection = conn
end function

'---------------------------------------------------
function getmdbrs( filename, source, cursor, password )
dim conn, rs

on error resume next
set getmdbrs = nothing
if len(password) = 0 then
set conn = getmdbconnection( filename )
else
set conn = getsecuredmdbconnection( filename, password )
end if
if conn is nothing then exit function

set rs = server.createobject("adodb.recordset")
if err.number <> 0 then exit function

rs.open source, conn, cursor, 2
if err.number <> 0 then exit function
set getmdbrs = rs
end function

'---------------------------------------------------
function getotherrs( datatype, path, sql, cursor )
dim conn, rs
on error resume next
set getotherrs = nothing

select case datatype
case "dbf"
set conn = getdbfconnection( path )
case "dbc"
set conn = getdbcconnection( path )
case "excel"
set conn = getexcelconnection( path )
case "text"
set conn = gettextconnection( path )
end select
if conn is nothing then exit function

set rs = server.createobject("adodb.recordset")
if err.number <> 0 then exit function

rs.open sql, conn, cursor, 2
if err.number <> 0 then exit function
set getotherrs = rs
end function

'---------------------------------------------------
function getsqlserverrs( computer, userid, password, db, source, cursor )
dim conn, rs

on error resume next
set getsqlserverrs = nothing
set conn = getsqlserverconnection( computer, userid, password, db )
if conn is nothing then exit function

set rs = server.createobject("adodb.recordset")
if err.number <> 0 then exit function

rs.open source, conn, cursor, 2
if err.number <> 0 then exit function
set getsqlserverrs = rs
end function
%>
使用方法是——复制下来存成一个文件,然后用#include “文件名”就可以调用里面的子程序了。
有什么问题可以一起探讨!!!


编辑:黑鹰 [发送给好友] [打印本页] [关闭窗口] [返回顶部]
上一篇:mysql的操作类
下一篇:mysql数据库函数详解
转载请注明来源:www.iyit.net
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。

 相关文章
最新更新 热点排行 推荐新闻
sql server 7.0与以前的版本相比,安全
设置proxy server和sql server实现互联
microsoft sql server 7.0安全问题   
mysql安全性指南(3)(转)           
mysql安全性指南 (2)(转)          
在frontpage 2000中插入flash动画
用frontpage 2000使图像“减肥”
提高frontpage 2002使用效率
用frontpage 2000创建网页动画
用frontpage 2000巧做样式表
用frontpage 2000制作鼠标光照特效
用frontpage轻松转换图片格式
frontpage10全透视教程(9)
frontpage10全透视教程(8)
frontpage10全透视教程(7)
sql server 7.0与以前的版本相比,安全
sql简明教程(6)
sql简明教程(5)
sql简明教程(4)
sql简明教程(3)
qq珊瑚虫外挂4.0版本发布!
多个广告位招商!
摄影后期系列一:1分钟为数码相片去红眼
qq挂机说明
asp进度条
photoshop通道抠图:给秀发飞扬的mm照
教您显示器亮度对比度的调节
新版上线,今日正式开通!!!
更多精彩图文广告等着您!
asp中使用sql语句教程
sql简明教程(1)
第二十章 开发delphi对象式数据管理功
sql简明教程(1)
vbscript和javascript互相调用 
jsp教程(四)-jsp actions的使用
操作系统被入侵后的修复过程
五一别忘电脑防毒 养成良好上网习惯
google对ie浏览器将捆绑搜索功能表担忧
新版上线,今日正式开通!!!
用photoshop创意图形“岁月”
摄影后期系列一:1分钟为数码相片去红眼

 友情链接
设置首 页 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接
copyrights © 2004-2006 iyit.net all rights reserved.
网站合作、广告联系qq:147007642、466949678
易特网络技术 点击这里给我发消息