欢迎光临
我们一直在努力

ASP编程常见问题 (转)

建站超值云服务器,限时71元/月

来源:www.yesky.com
1. 无法正确运行asp
当我们建立了一个asp文件,并且符合语法时,通过浏览器输入以下地址,或通过
资源管理器打开浏览:
c:\inetpub\wwwroot\a.asp
将出现无法运行的错误,并提示权限不对或文件无法访问,原因是,asp文件首先
要求站点是具备“执行(脚本)”属性的;然后要求按照url格式输入地址,而不
是dos格式,所以,请改正这两个错误。

2. 程序移动位置后,无法访问数据库
这种错误首先在odbc,如果odbc数据源设置正确,那么需要注意asp中打开数据库
的命令:conn.open 的参数是否正确。如果正确,则需要注意是否使用了global
.asa文件,该文件是asp连接数据库的配置文件,该文件内容如下:
<script language="vbscript" runat="server">
you can add special event handlers in this file that will get run aut
omatically when special active server pages events
occur. to create these handlers, just create a subroutine with a name
from the list below that corresponds to the event
you want to use. for example, to create an event handler for session_
onstart, you would put the following code into this
file (without the comments):
eventname description
session_onstart runs the first time a user runs any page in your appl
ication
session_onend runs when a users session times out or quits your appl
ication
application_onstart runs once when the first page of your application
is run for the first time by any user
application_onend runs once when the web server shuts down

</script>
<script language=vbscript runat=server>
sub session_onstart
==visual interdev generated – dataconnection startspan==
–project data connection
session("customers_connectionstring")="driver={sql server};server=(loc
al);uid=sa;pwd=;app=microsoft(r)developer studio;wsid=gregleak;databas
e=customers"
session("customers_connectiontimeout") = 15
session("customers_commandtimeout") = 30
session("customers_runtimeusername") = "sa"
session("customers_runtimepassword") = ""
==visual interdev generated – dataconnection endspan==
end sub
</script>
要注意其中的dsn,其中server后一定是数据库服务器名称,如果该处不正确,需
要改正。另外是uid和pwd是否正确;还有,如果open命令使用了session,则需要
注意
session("customers_runtimeusername") = "sa"
session("customers_runtimepassword") = ""
是否正确。

3. runat使用问题
  在脚本语法中,有runat参数,表示该脚本是运行在服务器上还是客户机上。
如果有runat=server则脚本运行在服务器上,由asp解释程序来解释执行,并将结
果传递给www服务器;否则就是运行在客户机上,由浏览器的脚本虚拟机解释执行
,这时,和一般的脚本没有区别。所以,一定要注意asp语法中的命令,如:req
uest,querystring,write等命令或对象必须在具备runat参数的脚本运行;而访
问html的form对象的脚本一定没有runat参数,因为html的form是客户机方面的对
象,服务器无法访问。

4. 无法向sql server插入日期字段
  如果遇到必须使用美国日期格式插入日期的情况,则需要在服务器的区域设
置上设置中国长日期格式,请特别注意,asp是在服务器上运行的,生成的html结
果传递给浏览器,所以,所有格式设置必须在服务器上。

5. 如何向客户机推送提示信息
  如果在服务器上判断访问错误,如注册失败、无权操作记录等需要提示用户
的信息。这个信息需要推送到客户机上,并出现提示窗口,这是经常遇到的问题
。这个时候,必须使用动态页面的方式,因为错误是在服务器上判断的,而提示
是在浏览器上出现的。我们 可以使用下面的asp来推送错误:
on error resume next
conn=server.createobject("adodb.connection")
conn.open "pubs","wlf",""
如果注册失败则错误数大于0
if conn.errors.count>0 then
‘以下代码生成客户机上的脚本语言,提供给浏览器执行
response.write "<script language=javascript>" & chr(13)
response.write "{" & chr(13)
response.write " window.alert("您无权访问数据库!")" & chr(13)
response.write "}" & chr(13)
response.write "</script >" & chr(13)
end if

6. 客户机尽量使用固定ip地址
由于asp连接数据库是定时的,默认是:
session("customers_connectiontimeout") = 15
session("customers_commandtimeout") = 30
两个设置决定的时间,超时后自动断开连接,所以,当刷新页面重新执行asp代码
时,如果ip分配时间不够(动态ip分配需要时间,比静态长很多!),可能无法
连接上,则出现错误信息,所以尽量用静态ip地址。  

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP编程常见问题 (转)
分享到: 更多 (0)