asp 连接SQL Server 问题(100分)

  • 主题发起人 主题发起人 土拨鼠
  • 开始时间 开始时间

土拨鼠

Unregistered / Unconfirmed
GUEST, unregistred user!
最近在学习Asp编程
连接程序如下
dim conn
set conn=server.createobject("ADODB.CONNECTION")
conn.open "driver={SQL Server};server=(local);uid=long;pwd=long;database=addr"
在另一页面程序为
<!--#include file="db.asp"-->
<%
。。。。。。
Set rs=Server.CreateObject("ADODB.Recordset")
sql="SELECT * FROM addressbook "
if Session("searchname")<>"" then
if Session("searchname")<>"reset" then
sql=sql &amp;
" where 姓名 LIKE "
sql=sql &amp;
"'%"
sql=sql &amp;
Session("searchname")
sql=sql &amp;
"%'"
sql=sql &amp;
" or "
sql=sql &amp;
" 部门 LIKE "
sql=sql &amp;
"'%"
sql=sql &amp;
Session("searchname")
sql=sql &amp;
"%'"
sql=sql &amp;
" or "

sql=sql &amp;
" 职务 LIKE "
sql=sql &amp;
"'%"
sql=sql &amp;
Session("searchname")
sql=sql &amp;
"%'"
sql=sql &amp;
" or "

sql=sql &amp;
" 住址 LIKE "
sql=sql &amp;
"'%"
sql=sql &amp;
Session("searchname")
sql=sql &amp;
"%'"
sql=sql &amp;
" or "

sql=sql &amp;
" 邮件地址 LIKE "
sql=sql &amp;
"'%"
sql=sql &amp;
Session("searchname")
sql=sql &amp;
"%'"
sql=sql &amp;
" or "

sql=sql &amp;
" 办公电话 LIKE "
sql=sql &amp;
"'%"
sql=sql &amp;
Session("searchname")
sql=sql &amp;
"%'"
sql=sql &amp;
" or "

sql=sql &amp;
" 家庭电话 LIKE "
sql=sql &amp;
"'%"
sql=sql &amp;
Session("searchname")
sql=sql &amp;
"%'"
sql=sql &amp;
" or "

sql=sql &amp;
" 手机号码 LIKE "
sql=sql &amp;
"'%"
sql=sql &amp;
Session("searchname")
sql=sql &amp;
"%'"
sql=sql &amp;
" or "

sql=sql &amp;
" 传呼机号码 LIKE "
sql=sql &amp;
"'%"
sql=sql &amp;
Session("searchname")
sql=sql &amp;
"%'"
sql=sql &amp;
" or "

sql=sql &amp;
" 备注 LIKE "
sql=sql &amp;
"'%"
sql=sql &amp;
Session("searchname")
sql=sql &amp;
"%'"
else

Session("searchname")=null
end if

end if
sql = sql &amp;
" ORDER by " &amp;
ordername
rs.open sql,conn,1,1
alls=rs.Recordcount
。。。。。。。。
单在打开网页时说在 rs.open sql,conn,1,1
错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E09)
/tmp/addr.asp, 第 95 行 (就是上面所在行)
请那位高手指点迷津,谢谢
 
将你的连接数据库的代码改为如下,
<%
Dim strConnString,DBConn

strConnString = "Provider=SQLOLEDB.1;
Persist Security Info=False;User ID=sa;
Initial Catalog=数据库名称;Data Source=你的机器的IP地址"
set DBConn = CreateObject("ADODB.Connection")
DBConn.Open strConnString
 
这是一个通过的例子。
<%@language=VBScript%>
<%
'-------------------------------------------------------
' 2001.8.1
' 数据库连接文件
'
' 需要文件(虚拟目录下):
' server.ini ->提供数据库配置信息
'-------------------------------------------------------
option explicit
'-------------------------------------------------------
'从server.ini中读出数据库配置
dim serverfile,fileobject,svr(5),sour,i,psize
Serverfile=server.MapPath("server.ini")
set FileObject=Server.CreateObject("Scripting.fileSystemObject")
set Sour=FileObject.OpenTextfile(Serverfile,1,true,False)
for i=0 to 5
svr(i)=Sour.Readline
next
Sour.close
'-------------------------------------------------------
'根据读出的配置信息连接到数据库
dim dbname,servername,loginname,lpasswd,conndb,pconn_connectionstring
dbname=svr(2)
servername=svr(3)
loginname=svr(4)
lpasswd=svr(5)
dbname=mid(dbname,instr(dbname,"=")+1,len(dbname))
servername=mid(servername,instr(servername,"=")+1,len(servername))
loginname=mid(loginname,instr(loginname,"=")+1,len(loginname))
lpasswd=mid(lpasswd,instr(lpasswd,"=")+1,len(lpasswd))
Application("ConnectionString") = "Driver={SQL Server};Database=" &amp;
dbname &amp;
";Server=" &amp;
servername &amp;
";UID=" &amp;
loginname &amp;
";PWD=" &amp;
lpasswd
SET conndb = Server.CreateObject ("ADODB.connection")
PConn_ConnectionString = Application("ConnectionString")
conndb.Open PConn_ConnectionString
%>
 
呵呵,其实这是ADO的问题.你只要在开头的地方加上一个
<!--#inclue virtual="adovbs.inc"-->,这样应该就行了
 
多人接受答案了。
 
后退
顶部