菜鸟求助:asp怎么连接SQL SERVER

小皮 2008-03-31 09:27:59
刚学asp,连不上SQL server。
-------
dim conn,rs
set conn = server.createobject("adodb.connection")
conn.open "driver={sql server};database=dbname;server=local;uid=;pwd="
Set rs = Server.CreateObject("ADODB.RecordSet")
SQL = "select * from table"
rs.open sql,conn,3,2
--------
不知道上面这段代码,是不是要先设置odbc?
我不会设置odbc,谁教教我呀?
我QQ:7107678,有没有高手留个QQ给我,如果在上海的,我请喝coffee啦。
呵呵。
...全文
107 点赞 收藏 14
写回复
14 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
苍白之月 2008-04-04
[Quote=引用 11 楼 superwfei 的回复:]
http://www.connectionstrings.com/
[/Quote]

建议去看看 对深入开发很有好处^_^

[Quote=引用 2 楼 luxu001207 的回复:]
conn.open "driver={sql server};database=dbname;server=(local);uid=;pwd="
郁闷,这破鼠标真难用。。。50%的几率单击变双击
[/Quote]

不着急 不着急
回复
小皮 2008-04-03
搞订了。呵呵
回复
fishidea 2008-04-01
<%
Const SqlDatabaseName = "数据库名"
Const SqlPassword = "数据库密码"
Const SqlUsername = "数据库用户名,一般为sa"
Const SqlLocalName = "数据库IP地址,本地用(local)"

Dim ConnStr
ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"
Response.End
End If
%>

给分啦~^_^
回复
braveboy 2008-04-01
<%
dim conn

if not isObject(conn) then openconn
sub openconn ()
const uname = "sa"
const pwd = "password"
const serverip = "(local)"
const dbase = "cute"
const dbty = "SQL" '数据库类型:ACCESS access数据库
dim connstr
const DbPath = "E:\网站\\data\#ITlearner.asp"
if dbty = "ACCESS" then
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;"_
&"Data Source="& DbPath & ";"_
& "Jet OLEDB:Database Password=;"
else
connstr="Provider = Sqloledb; User ID = " & uname & "; Password = " & pwd & "; Initial Catalog = " & dbase & "; Data Source = " & serverip & ";"
end if
'无需配置dsn

set conn = server.createobject("adodb.connection")
conn.open connstr
If Err Then
Err.Clear
Set Conn = Nothing
Response.Write connstr
Response.End
End If
end sub

sub closeconn()
if isObject(conn) then conn.close:set conn = nothing
end sub
%>
回复
文盲老顾 2008-04-01
http://www.connectionstrings.com/
回复
niansen 2008-04-01
dim conn,rs
set conn = server.createobject("adodb.connection")
conn.ConnectionString="driver={sql server};database=dbname;server=local;uid=sa;pwd=sa"

conn.Execute = "select * from table"
回复
sniper1534 2008-03-31
<%
dim conn
set conn=server.createobject("ADODB.connection")
con.open "PROVIDER=SQLOLEDB;DATA SOURCE=SQL服务器名称或IP地址;UID=sa;PWD=数据库密码;DATABASE=数据库名称
%>
替换相应的字段即可

建立记录集对象:

set rs=server.createobject("adodb.recordset")
rs.open SQL语句,conn,3,2

回复
yongshi128 2008-03-31
楼主再给点耐心好好调试一下吧
上面几位都说出了方法
当初我也经历过你这个阶段,慢慢来吧。
回复
小皮 2008-03-31
代码
dim conn,rs
set conn = server.createobject("adodb.connection")
conn.open "Provider=SQLOLEDB;Data source=local;Initial Catalog=moTest;User ID=Administrator;Password=123456;"
Set rs = Server.CreateObject("ADODB.RecordSet")
SQL = "select * from table1"
rs.open sql,conn,1,1
回复
小皮 2008-03-31
代码是:
<%
dim conn,rs
set conn = server.createobject("adodb.connection")
conn.open "Provider=SQLOLEDB;Data source=local;Initial Catalog=moTest;User ID=Administrator;Password=123456;"
Set rs = Server.CreateObject("ADODB.RecordSet")
SQL = "select * from table1"
rs.open sql,conn,1,1
%>
回复
小皮 2008-03-31
还是连不上呀。5555
谁可以加我QQ呀。
我的数据库叫moTest,SQL 帐号是Administrator/123456。
asp页面是:http://localhost/temp/temp.asp
报错:

Microsoft VBScript 编译器错误 错误 '800a03f6'

缺少 'End'

/iisHelp/common/500-100.asp,行242

Microsoft OLE DB Provider for ODBC Drivers 错误 '80004005'

[Microsoft][ODBC 驱动程序 管理器] 未发现数据源名称并且未指定默认驱动程序

/temp/temp.asp,行17


回复
xler2008 2008-03-31
在管理工具里做个odbc源 db1.dsn
set conn=server.CreateObject("adodb.connection")
conn.Open "filedsn=" & 路径/db1.dsn
回复
Atai-Lu 2008-03-31
conn.open "driver={sql server};database=dbname;server=(local);uid=;pwd="
郁闷,这破鼠标真难用。。。50%的几率单击变双击
回复
hookee 2008-03-31
oledb或odbc直接连接 可不设dsn
在数据库内建立相关的帐号和角色即可
set conn = server.createobject("adodb.connection")
conn.open "Provider=SQLOLEDB;Data source=127.0.0.1;Initial Catalog=db;User ID=sa;Password=;"
Set rs = Server.CreateObject("ADODB.RecordSet")
SQL = "select * from table"
rs.open sql,conn,1,1
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2008-03-31 09:27
社区公告
暂无公告