温柔网

 找回密码
 注册

查看: 1193|回复: 1

主题:ASP中各种数据库连接代码

[复制链接]
发表于 2005-12-13 20:48:01 | 显示全部楼层 |阅读模式

最近看到有不少朋友在问关于数据库连接代码的问题,找了这篇东西给大家看看,希望有帮助


MS Access数据库连接

用DSN连接并且没有用户名和密码:

<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "YourDSNName"
%>

用DSN连接并且有用户名和密码:

<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "YourDSNName","username","password"
%>

用实际的数据库绝对路径连接:

<%
Set conn = Server.CreateObject("ADODB.Connection")
Strconn="DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ=e:\yanhang\database.mdb"
conn.Open Strconn
%>

用实际的数据库相对路径连接:

<%
Set conn = Server.CreateObject("ADODB.Connection")
Strconn="DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ=" & Server.MapPath("/database/yanhang.mdb")
conn.Open Strconn
%>


MS SQL Server数据库连接

用DSN连接:

<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "DSN=MyDSN;UID=userWD=password;DATABASE=databasename"
%>

不用DSN连接:

<%
Set conn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={SQL Server};SERVER=ServerName;UID=USERWD=password;DATABASE=databasename"
conn.open DSNtemp
%>


FoxPro数据库连接

<%
Set Conn = Server.CreateObject("ADODB.connection")
ConnStr= "Driver=Microsoft Visual Foxpro Driver; UID=userID;SourceType=DBC;SourceDB=C:\yanhang\database.dbc"
Conn.Open ConnStr
%>


Oracle数据库连接:

<%
set conn=server.createobject("adodb.connection")
conn.cursorlocation=adUseClient
DSNTemp="rovider=MSDAORA.1;Password=xxxxx;User ID=yanhang;Data Source=xxx.world"
conn.open DSNtemp
%>

发表于 2005-12-22 06:41:45 | 显示全部楼层
[wawa3]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|温柔网 ( 浙ICP备13033583号-8 )

GMT+8, 2024-11-21 23:52 , Processed in 0.034774 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表