用dreamweaver做完asp网页上传到空间后无法连接数据库,如何解决?
我用Dreamweaver做的网页,想做一个能读取数据库的页面,使用本地测试没有问题,可以将数据库的内容读出来,代码如下:<%@LANGUAGE="VBSCRIPT"CO...
我用Dreamweaver做的网页,想做一个能读取数据库的页面,使用本地测试没有问题,可以将数据库的内容读出来,代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/s_link.asp" -->
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_s_link_STRING
Recordset1_cmd.CommandText = "SELECT * FROM sheet1"
Recordset1_cmd.Prepared = true
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
Dim link_name
Dim link_name_cmd
Dim link_name_numRows
Set link_name_cmd = Server.CreateObject ("ADODB.Command")
link_name_cmd.ActiveConnection = MM_s_link_STRING
link_name_cmd.CommandText = "SELECT * FROM sheet1"
link_name_cmd.Prepared = true
Set link_name = link_name_cmd.Execute
link_name_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
link_name_numRows = link_name_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
......
s_link.asp文件的内容如下:
<%
' FileName="Connection_odbc_conn_dsn.htm"
' Type="ADO"
' DesigntimeType="ADO"
' HTTP="false"
' Catalog=""
' Schema=""
Dim MM_s_link_STRING
MM_s_link_STRING = "dsn=datatestdb;"
%>
但空间里要求把数据库放在一个名为DB的文件夹下,并且给出了提示代码
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
strConnection = "DRIVER=Microsoft Access Driver(*.mdb);DBQ=" & Server.MapPath("/USERNAME/db/yourdatabase.mdb")
oConn.Open(strConnection)
....
...
oConn.Close
请教高手我的代码应该如何修改?
第一段代码好像有点儿问题,我又改了一下,本地可以运行,如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/s_link.asp" -->
<%
Dim link_name
Dim link_name_cmd
Dim link_name_numRows
Set link_name_cmd = Server.CreateObject ("ADODB.Command")
link_name_cmd.ActiveConnection = MM_s_link_STRING
link_name_cmd.CommandText = "SELECT * FROM sheet1"
link_name_cmd.Prepared = true
Set link_name = link_name_cmd.Execute
link_name_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
link_name_numRows = link_name_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
......
另外,空间是支持ASP和ACESS的,我用的也是ACESS数据库 展开
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/s_link.asp" -->
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_s_link_STRING
Recordset1_cmd.CommandText = "SELECT * FROM sheet1"
Recordset1_cmd.Prepared = true
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
Dim link_name
Dim link_name_cmd
Dim link_name_numRows
Set link_name_cmd = Server.CreateObject ("ADODB.Command")
link_name_cmd.ActiveConnection = MM_s_link_STRING
link_name_cmd.CommandText = "SELECT * FROM sheet1"
link_name_cmd.Prepared = true
Set link_name = link_name_cmd.Execute
link_name_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
link_name_numRows = link_name_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
......
s_link.asp文件的内容如下:
<%
' FileName="Connection_odbc_conn_dsn.htm"
' Type="ADO"
' DesigntimeType="ADO"
' HTTP="false"
' Catalog=""
' Schema=""
Dim MM_s_link_STRING
MM_s_link_STRING = "dsn=datatestdb;"
%>
但空间里要求把数据库放在一个名为DB的文件夹下,并且给出了提示代码
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
strConnection = "DRIVER=Microsoft Access Driver(*.mdb);DBQ=" & Server.MapPath("/USERNAME/db/yourdatabase.mdb")
oConn.Open(strConnection)
....
...
oConn.Close
请教高手我的代码应该如何修改?
第一段代码好像有点儿问题,我又改了一下,本地可以运行,如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/s_link.asp" -->
<%
Dim link_name
Dim link_name_cmd
Dim link_name_numRows
Set link_name_cmd = Server.CreateObject ("ADODB.Command")
link_name_cmd.ActiveConnection = MM_s_link_STRING
link_name_cmd.CommandText = "SELECT * FROM sheet1"
link_name_cmd.Prepared = true
Set link_name = link_name_cmd.Execute
link_name_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
link_name_numRows = link_name_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
......
另外,空间是支持ASP和ACESS的,我用的也是ACESS数据库 展开
2个回答
展开全部
<%
dim conn,connstr
on error resume next
connstr="DBQ="+server.mappath("data/数据库名.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
Set conn=Server.CreateObject("ADODB.CONNECTION")
conn.open connstr
%>
把上面这段代码修改数据库名称和路径后保存为另一个asp文件,如"conn.asp"
在你要连接数据库的页面开头加上下面这句就可以了。
<!--#include file="conn.asp"-->
dreamweaver做的是绝对路径,上传之后肯定上用不了的。新手都会遇到这个问题。
dim conn,connstr
on error resume next
connstr="DBQ="+server.mappath("data/数据库名.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
Set conn=Server.CreateObject("ADODB.CONNECTION")
conn.open connstr
%>
把上面这段代码修改数据库名称和路径后保存为另一个asp文件,如"conn.asp"
在你要连接数据库的页面开头加上下面这句就可以了。
<!--#include file="conn.asp"-->
dreamweaver做的是绝对路径,上传之后肯定上用不了的。新手都会遇到这个问题。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询