asp如何连接sql数据库?

bernice99 2004-04-08 02:37:35
一些本机的信息是怎么按格式写的。
...全文
109 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
bernice99 2004-09-03
结帖
回复
AspDelphi 2004-04-09
不必设置ODBC直连就可以
set conn = server.createobject("adodb.connection")
conn.open "driver={sql server};database=数据库名称;server=(local);uid=sa;pwd="
回复
bernice99 2004-04-09
如果我的sql server是按window身份验证的,是不是连接时就写:

set conn = server.createobject("adodb.connection")
conn.open "driver={sql server};database=数据库名称;server=(local);uid=;pwd="

这样就行了?uid和pwd那是空的呢?
回复
blueice2002 2004-04-09
asp与sql server 数据库的连接
<%
'连接数据库————————————————————————————
set conn=server.createobject("adodb.connection")
Connstr="Provider=SQLOLEDB;Data Source=127.0.0.1;UID=sa;PWD=sa;DataBase=web"
'打开数据库——————————————————————————————————
conn.open connstr
'写数据查询语句————————————————————————
set rs=conn.execute("select * from asp where id>2")
'输出查询结果——————————————————————————
do until rs.eof
response.write rs("id")&"<br>"
response.write rs("name")&"<br>"
rs.movenext
loop
%>
************************************
asp与access 数据库的连接
********************************
<% dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("login.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err then
err.clear
else
conn.open connstr
if err then
err.clear
end if
end if
set rs=conn.execute("select * from login_info where id>1")
do until rs.eof
response.write rs("id")&"<br>"
response.write rs("username")&"<br>"
response.write rs("password")&"<br>"
rs.Movenext
loop %>

*****************************************************
*****************************************************
<!--#include file="conn.asp"-->
<%
set rs=conn.execute("select * from login_info where id>2")
'set rs=server.createobject("adodb.recordset")
'sql="select * from login_info where id > ='1' "
'rs.open sql,conn,1,1
do until rs.eof
response.write rs("id")&"<br>"
response.write rs("username")&"<br>"
response.write rs("password")&"<br>"
rs.Movenext
loop
%>

**********************************************************
***********************************************************

连结其他数据库的方法(*.dbf,*.txt,excel,foxpro等) ----收藏
2002-10-30 18:41:05 浏览次数:145

'连结dbf文件
<%
' 建立Connection 对象
Set conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Visual FoxPro Driver};"
SourceType = "SourceType=DBF;"
DBPath = "SourceDB=" & Server.MapPath( "Dbf" )

' 调用Open 方法连接数据库
conn.Open Driver & SourceType & DBPath

Set rs = Server.CreateObject("ADODB.Recordset")
' 打开数据源,参数二为Connection对象
rs.Open "Select * From sample", conn, 2, 2
%>
'连结foxpro文件
<%
' 建立Connection 对象
Set conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Visual FoxPro Driver};"
SourceType = "SourceType=DBC;"
DBPath = "SourceDB=" & Server.MapPath( "Dbf/Sample.dbc" )

' 调用Open 方法连接数据库
conn.Open Driver & SourceType & DBPath

Set rs = Server.CreateObject("ADODB.Recordset")
' 打开数据源,参数二为Connection对象
rs.Open "Select * From sample", conn, 2, 2
%>

'连结excel文件
<%
' 建立Connection对象
Set conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Excel Driver (*.xls)};"
DBPath = "DBQ=" & Server.MapPath( "Sample.xls" )

' 调用Open 方法连接数据库
conn.Open Driver & DBPath

Set rs = Server.CreateObject("ADODB.Recordset")
' 打开数据源,参数二为Connection对象
rs.Open "Select * From [成绩单$]", conn, 2, 2
%>

'连结txt文件
<%
' 建立Connection 对象
Set conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Text Driver (*.txt; *.csv)};"
DBPath = "DBQ=" & Server.MapPath( "Text" )

' 调用Open 方法连接数据库
conn.Open Driver & DBPath

Set rs = Server.CreateObject("ADODB.Recordset")
' 打开数据源,参数二为Connection对象
rs.Open "Select * From sample.txt", conn, 2, 2
%>






SELECT语法:(基本)



*************************************************************
**********************************************************
SELECT [DISTINCT]
(column [{, column } ] )| *
FROM table [ { , table} ]
[ORDER BY column [ASC] | [DESC
[{ , column [ASC] | [DESC } ] ]
WHERE predicate [ { logical-connector predicate } ];
------------------------------------------------------

INSERT语法:

INSERT INTO table
[(column { ,column})]
VALUES
(columnvalue [{,columnvalue}]);
------------------------------------------------------

UPDATE语法:

UPDATE table
SET column = value [{, column = value}]
[ WHERE predicate [ { logical-connector predicate}]];
------------------------------------------------------

DELETE语法:

DELETE FROM table
[WHERE predicate [ { logical-connector predicate} ] ];
------------------------------------------------------
blueice2002 2003-03整理
回复
swich 2004-04-09
http://www.connectionstrings.com/
回复
fxbb 2004-04-09
我出的错也和你的差不多,明明是这样设的,为什么也是报和你一样的错呢???顶!!!
回复
bernice99 2004-04-08
我的sql server连接是按window身份验证进入的,连接时不要密码。
我在odbc已经设定好了数据源,并且测试成功了。
而我在asp连接数据库中写的程序:

set objconn=server.createobject("adodb.connection")
objconn.open "dsn=mydb;database=db2;uid=;pwd=;"
却说错误Microsoft OLE DB Provider for ODBC Drivers (0x80040E4D)

怎么回事?
回复
zhonghuashen 2004-04-08
zwonline99(zwonline)都是用的字符驱动,有没有oledb的?
回复
zhonghuashen 2004-04-08
好,收藏。
回复
AspDelphi 2004-04-08
http://www.connectionstrings.com/
回复
kenvinp 2004-04-08
faq
搜索一下吧
回复
andraw2002 2004-04-08
全部都在上面了
回复
zwonline99 2004-04-08
常用六种数据库连接方式:

1.对在access数据库而言,数据库连接的asp程式码如下:set conn = server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq=数据库名称;uid=sa;pwd="
其中在dbq直接设定access数据库的真实路径名称。您可以使用server.mappath("数据库名称名称") 以取得数据库的真实地址如下:
conn.open "driver={microsoft access driver (*.mdb)};dbq=" & server.mappath("数据库名称") & ";uid=sa;pwd="

2.对在sql server数据库而言,数据库连接的asp程式码如下:
set conn = server.createobject("adodb.connection")
conn.open "driver={sql server};database=数据库名称;server=(local);uid=sa;pwd="

3.对在oracle数据库而言,数据库连接的asp程式码如下:
set conn = server.createobject("adodb.connection")
conn.open "driver={microsoft odbc for oracle};uid=xxx;pwd=yyy;server=sss"

4.对在excel而言,数据库连接的asp程式码如下:
set conn = server.createobject("adodb.connection")
conn.open "driver={microsoft excel driver (*.xls)};dbq=数据库名称"

5.对在dbase数据库而言,数据库连接的asp程式码如下:
set conn = server.createobject("adodb.connection")
conn.open "driver={microsoft dbase driver (*.dbf)};dbq=数据库名称"

6.对在text名称而言,数据库连接的asp程式码如下:
set conn = server.createobject("adodb.connection")
conn.open "driver= {microsoft text driver (*.txt; *.csv)};dbq=数据库名称"
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

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