ASP里怎么连sql server数据库?谢谢了~~~

takkicai 2004-04-11 01:40:44
句子怎么写?谢谢各位了~~~拜托~~~
...全文
122 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
fxbb 2004-04-11
set conn=Server.CreateObject(ADODB.Connection)
conn.Open"PROVIDER=SQLOLDB;DATA SOURCE=数据库IP(localhost本地);
UserID=sa;PassWard=sa;DATABASE=databasename"
set rs=Server.CreateObject(ADODB.Recordset)
sqlstr="select * from tablename"
rs.Open(sqlstr,conn,3,1)

这个网址很不错;http://www.connectionstrings.com/
回复
zcxc 2004-04-11
gz
回复
Newrocky 2004-04-11
[连接SQL数据库]
set dcnDB = server.createobject("ADODB.CONNECTION")
dcnDB.open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=帐号;pwd=密码;Initial Catalog=表名;Data Source=数据库IP(localhost本地)"
set rsDB = server.createobject("ADODB.RECORDSET")
回复
hblzg 2004-04-11
<%
dim conn,rs,sql,uid,pwd,database
uid="sa" '用户
pwd="sa" '密码
serverip="127.0.0.1" '服务器地址
database="office"'数据库名字

'进行连接错误的判断
on error resume next

set conn=server.createobject("ADODB.connection")
set rs=server.createobject("adodb.recordset")
conn.Open "driver={SQL Server};server="&serverip&";UID="&uid&";pwd="&pwd&";database="&database

if err.number<>0 then
response.write "连接数据库失败,请稍侯重试……"
response.end
end if

%>

这个添加上了,连接服务器出错时候的判断了
回复
benben168 2004-04-11
<%
option explicit
dim startime,endtime,conn,connstr,db
startime=timer()
connstr="driver=;server=sqlserverpmq;uid=sa;pwd=sa;database=admin"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connstr
function CloseDatabase
Conn.close
Set conn = Nothing
End Function
%>
回复
takkicai 2004-04-11
谢谢了~~~~
回复
大山里的松 2004-04-11
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;PWD=;Initial Catalog=testdb;Data Source=(local)"
conn.Open connstr

dim conn
set conn=server.CreateObject("adodb.connection")
connstr = "DSN=***;UID=***;PWD=***"
conn.Open connstr


dim conn,sql
set conn=server.createobject("adodb.connection")
sql="Driver={SQL Server};Server=WALLYSOFT-SERVE;Database=lubai;UID=sa;PWD=;"
conn.open sql
'Server为数据库服务器,Database为数据库名,UID为用户名PWD库密码
回复
lubaixu 2004-04-11
<%
'连接SQL Server数据库
dim conn,sql
set conn=server.createobject("adodb.connection")
sql="Driver={SQL Server};Server=WALLYSOFT-SERVE;Database=lubai;UID=sa;PWD=;"
conn.open sql
'Server为数据库服务器,Database为数据库名,UID为用户名PWD库密码
%>
回复
reidli 2004-04-11
用dns也可以,在odbc里面设置好,
然后
<%
dim conn
set conn=server.CreateObject("adodb.connection")
connstr = "DSN=***;UID=***;PWD=***"
conn.Open connstr
%>
回复
TrueAndFalse 2004-04-11
http://www.connectionstrings.com
回复
51windows 2004-04-11
set conn=Server.CreateObject("ADODB.Connection")
conn.Open ("driver={SQL Server};server=localhost;uid=sa;pwd=sa;database=database;")


http://www.51windows.net/pages/ConnectionStrings.htm
回复
mikespook 2004-04-11
<%
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;PWD=;Initial Catalog=testdb;Data Source=(local)"
conn.Open connstr
%>
回复
yiwenlv 2004-04-11
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=user;PWD=password;DATABASE=databasename"
%>

不用DSN连接:

<%
Set conn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={SQL Server};SERVER=ServerName;UID=USER;PWD=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="Provider=MSDAORA.1;Password=xxxxx;User ID=yanhang;Data Source=xxx.world"
conn.open DSNtemp
%>
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告