但是,由于asp是基于internet/intranet方式的,它和传统的c/s结构毕竟有所不同,这样在开发中也要注意一些细节问题。本文讲述常见的一些问题,并给出解决方法。
问题描述
a. 无法正确运行asp
当我们建立了一个asp文件,并且符合语法时,通过浏览器输入以下地址,或通过资源管理器打开浏览:
c:\inetpub\wwwroot\a.asp
将出现无法运行的错误,并提示权限不对或文件无法访问,原因是,asp文件首先要求站点是具备“执行(脚本)”属性的;然后要求按照url格式输入地址,而不是dos格式,所以,请改正这两个错误。
b. 程序移动位置后,无法访问数据库
这种错误首先在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 automatically 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 application
session_onend runs when a users session times out or quits your application
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=(local);uid=sa;pwd=;app=microsoft(r)developer studio;wsid=gregleak;database=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") = ""
是否正确。
c. runat使用问题
在脚本语法中,有runat参数,表示该脚本是运行在服务器上还是客户机上。如果有runat=server则脚本运行在服务器上,由asp解释程序来解释执行,并将结果传递给www服务器;否则就是运行在客户机上,由浏览器的脚本虚拟机解释执行,这时,和一般的脚本没有区别。所以,一定要注意asp语法中的命令,如:request,querystring,write等命令或对象必须在具备runat参数的脚本运行;而访问html的form对象的脚本一定没有runat参数,因为html的form是客户机方面的对象,服务器无法访问。
d. 无法向sql server插入日期字段
如果遇到必须使用美国日期格式插入日期的情况,则需要在服务器的区域设置上设置中国长日期格式,请特别注意,asp是在服务器上运行的,生成的html结果传递给浏览器,所以,所有格式设置必须在服务器上。
e. 如何向客户机推送提示信息
如果在服务器上判断访问错误,如注册失败、无权操作记录等需要提示用户的信息。这个信息需要推送到客户机上,并出现提示窗口,这是经常遇到的问题。这个时候,必须使用动态页面的方式,因为错误是在服务器上判断的,而提示是在浏览器上出现的。我们 可以使用下面的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
f. 客户机尽量使用固定ip地址
由于asp连接数据库是定时的,默认是:
session("customers_connectiontimeout") = 15
session("customers_commandtimeout") = 30
两个设置决定的时间,超时后自动断开连接,所以,当刷新页面重新执行asp代码时,如果ip分配时间不够(动态ip分配需要时间,比静态长很多!),可能无法连接上,则出现错误信息,所以尽量用静态ip地址。
总结
使用asp编程是很方便的。由于ado跨越了odbc,形成具备多线程处理能力的数据库操作方式,并且是在服务器上运行,虽然增加了服务器的压力,好在现在的服务器(哪怕是pc服务器)处理能力都非常强,这样反而发挥了服务器的效率。另外,由于asp可以和activex控件进行良好的接口,也使开发者容易根据自己的需要扩充程序,并直接建立在asp编程环境上,唯一需要注意的是,一定要以internet/intranet的思路设计和编写程序,否则将事倍功半。
文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




