ASP连接access和mssql数据库的全能代码
来源:CSDN 时间:2008-10-12 13:17:00
解决了ACCESS数据库路径的问题!
采用DBType=0或DBType=1来区分AC库还是MSSQL库
具体采用AC库时应注意的事项,请看程序说明
Dim DBType,Conn,StrConn
DBType=0 '0为Access数据库,1为MSSQL数据库
If(DBType=0) Then
'ACCESS数据库
Dim DbFolderName,DbFolder_Path,SiteFolder
DbFolderName="ArticleData" '数据库所在文件夹名称
DbFolder_Path = Server.MapPath(DbFolderName) '数据库所在路径
SiteFolder="Article" '系统所在根目录名称
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)};DBQ=" & Session("RootDir") & "\"& DbFolderName & "\Data.mdb" '连接到数据库
Conn.Open StrConn
ElseIf(DBType=1) Then
'MSSQL SERVER数据库
Dim DBUserID,DBPassWord,DBName,DBIP
'修改以下信息以适合你的网站
DBUserID="sa" '数据库登陆名
DBPassWord="" '数据库密码
DBName="dbname" '数据库名称
DBIP="local" '数据库所在地址,如果是本地数据库则为:(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
标签:access,mssql,数据库,连接,代码
0
投稿
猜你喜欢
Python读取excel文件中带公式的值的实现
2022-04-05 14:03:27
python实现接口并发测试脚本
2023-04-20 05:06:15
Python词法结构
2022-01-10 00:33:21
centos下安装配置phpMyAdmin的方法步骤
2023-11-09 01:27:11
python GUI模拟实现计算器
2023-01-08 22:20:40
python用tkinter开发的扫雷游戏
2022-05-16 18:39:40
分享4个最受欢迎的大数据可视化工具
2022-12-23 02:45:18
在django项目中,如何单独运行某个python文件
2023-04-27 07:37:22
如何优化JavaScript脚本的性能
2008-02-19 21:47:00
Vue2 响应式系统之深度响应
2024-04-26 17:40:05
一文详解typeScript的extends关键字
2024-02-24 11:30:02
让程序员都费解的10大编程语言特性
2023-09-12 03:56:49
使用Dreamweaver便捷技巧方法十六则
2010-07-02 16:28:00
Python中的rfind()方法使用详解
2022-05-05 21:30:54
优化MySQL数据库查询的三种方法
2009-03-09 15:19:00
golang中json的omitempty使用操作
2024-05-13 09:06:44
用Python实现批量生成法务函代码
2022-05-27 15:05:28
matplotlib画混淆矩阵与正确率曲线的实例代码
2021-09-21 05:41:10
pandas统计重复值次数的方法实现
2022-11-09 03:27:58
使用keras实现非线性回归(两种加激活函数的方式)
2023-07-23 23:33:53