ASP 中连接 MSSQL的几种方法
类别: ASP教程
方法一:
<%
dim conn
set conn=server.createobject("ADODB.connection")
conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=db.janusgroup.cn;UID=web286418;PWD=j2z0h1v2;DATABASE=www_janusgroup_cn"
Set conn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={SQL Server};SERVER=db.janusgroup.cn;UID=web286418;PWD=j2z0h1v2;DATABASE=www_janusgroup_cn"
conn.open DSNtemp
%>
方法二:
<%
option explicit
dim startime
dim conn
dim connstr
dim db,pass_word,User_ID,Data_Source
startime=timer()
db="www_db_cn" \'数据库名称
Pass_word="0h1v2" \'Password=帐号密码
User_ID="web2-sql8" \'User ID=登陆帐号
Data_Source="100.100.100.100" \'Data Source=服务名称或者ip
Set conn = Server.CreateObject("ADODB.Connection")
connStr="Provider=SQLOLEDB.1;Password=\'"&pass_word&"\';Persist Security Info=True;User ID=\'"&User_ID&"\';Initial Catalog=\'"&db&"\';Data Source=\'"&Data_Source&"\'"
conn.Open connstr
function CloseDb
Conn.close
Set conn = Nothing
End Function
%>
<%
dim conn
set conn=server.createobject("ADODB.connection")
conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=db.janusgroup.cn;UID=web286418;PWD=j2z0h1v2;DATABASE=www_janusgroup_cn"
Set conn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={SQL Server};SERVER=db.janusgroup.cn;UID=web286418;PWD=j2z0h1v2;DATABASE=www_janusgroup_cn"
conn.open DSNtemp
%>
方法二:
<%
option explicit
dim startime
dim conn
dim connstr
dim db,pass_word,User_ID,Data_Source
startime=timer()
db="www_db_cn" \'数据库名称
Pass_word="0h1v2" \'Password=帐号密码
User_ID="web2-sql8" \'User ID=登陆帐号
Data_Source="100.100.100.100" \'Data Source=服务名称或者ip
Set conn = Server.CreateObject("ADODB.Connection")
connStr="Provider=SQLOLEDB.1;Password=\'"&pass_word&"\';Persist Security Info=True;User ID=\'"&User_ID&"\';Initial Catalog=\'"&db&"\';Data Source=\'"&Data_Source&"\'"
conn.Open connstr
function CloseDb
Conn.close
Set conn = Nothing
End Function
%>
- 上一篇: 用VBSCRIPT实现对WINDOWS注册表的修改
- 下一篇: 防止用户上传产生无效文件源码
-= 资 源 教 程 =-
文 章 搜 索