遇到错误!描述:变量未定义。编号:500。来源:Microsoft VBScript运行时错误。 [英] An Error Was Encountered!. Description: Variable is undefined. Number: 500. Source: Microsoft VBScript runtime error.

查看:89
本文介绍了遇到错误!描述:变量未定义。编号:500。来源:Microsoft VBScript运行时错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在页面上编写代码来上传文件。我想测试这段代码,但我在之前已存在的函数中遇到数据库错误。我检查了代码是否有缺失变量,如果有的话,但一切似乎都没问题。由于这个原因,我无法测试我写的代码。我收到以下错误:



遇到错误!描述:变量未定义。编号:500。来源:Microsoft VBScript运行时错误。

DBGetCoursesJS()中遇到数据库错误。请联系您的SharedHR管理员。



以下是该方法的代码:

  function  DBGetCoursesJS()
Dim objRS,sSQL
Dim strSelected

DBGetCoursesJS = false
sSQL = SELECT CourseID,CourseName,DefaultVendor,DefaultTrainer,DefaultLocation,DefaultHours,DefaultLifeSpan
sSQL = sSQL& FROM TrainingCourses
sSQL = sSQL& WHERE CompID =& intCompID
sSQL = sSQL& AND ProgramID =& intProgramID
设置 objRS = Server.CreateObject( ADODB.Recordset
objRS.Open sSQL,objConnect,adOpenStatic,adLockReadOnly,adCmdText
if DBCheckError()然后
strClientMessage = strClientMessage& 在DBGetCoursesJS()中遇到数据库错误。请联系您的& strAppTitle& 管理员。& vbCRLF
DbGetCoursesJS = false
退出 function
end if

Dim iCnt,strArrayItem
iCnt = 0
while objRS.EOF
strArrayItem =
strArrayItem = arrCourses [& iCnt& ] =新课程(
strArrayItem = strArrayItem& objRS( CourseID)&
strArrayItem = strArrayItem& objRS( CourseName)&
strArrayItem = strArrayItem& objRS( DefaultVendor)&
strArrayItem = strArrayItem& objRS( DefaultTrainer)&
strArrayItem = strArrayItem& objRS( DefaultLocation)&
strArrayItem = strArrayItem& objRS( DefaultHours)&
strArrayItem = strArrayItem& objRS( DefaultLifeSpan)& );
Response.Write(strArrayItem& vbNewLine)
iCnt = iCnt + 1
objRS.MoveNext
wend
objRS.Close
Set objRS = Nothing
DbGetCoursesJS = true
结束 功能

解决方案

无论您的问题是什么,您是否知道此实现易受 SQL注入 [ ^ ]?



我建议你宁愿使用存储过程edure [ ^ ]或参数化查询 [ ^ ]。

你的最后一行不应该是结束函数吗?

另外,尝试使用ado常量的等价数字,并且不要使用adCmdText。


I am writing code on a page to upload files.I wanted to test this code but I am getting database error in the functions which already existed before. I have checked the code for missing variables if any but everything seems to be fine. Due to this I am not able to test the code I wrote.I get the following error:

An Error Was Encountered!. Description: Variable is undefined. Number: 500. Source: Microsoft VBScript runtime error.
Database error encountered in DBGetCoursesJS(). Please contact your SharedHR Administrator.

Following is the code for the method:

function DBGetCoursesJS()
	Dim objRS, sSQL
	Dim strSelected

	DBGetCoursesJS = false
	sSQL = "SELECT CourseID, CourseName, DefaultVendor, DefaultTrainer, DefaultLocation, DefaultHours, DefaultLifeSpan"
	sSQL = sSQL &  " FROM TrainingCourses"
	sSQL = sSQL & " WHERE CompID = " & intCompID
	sSQL = sSQL &   " AND ProgramID = " & intProgramID
	Set objRS = Server.CreateObject("ADODB.Recordset")
	objRS.Open sSQL, objConnect, adOpenStatic, adLockReadOnly, adCmdText
	if DBCheckError() then
		strClientMessage = strClientMessage & "Database error encountered in DBGetCoursesJS().  Please contact your " & strAppTitle & " Administrator." & vbCRLF
		DbGetCoursesJS = false
		exit function
end if

	Dim iCnt, strArrayItem
	iCnt = 0
	while not objRS.EOF
		strArrayItem = ""
		strArrayItem = "arrCourses[" & iCnt & "] = new Course("""
		strArrayItem = strArrayItem & objRS("CourseID") & """, """
		strArrayItem = strArrayItem & objRS("CourseName") & """, """
		strArrayItem = strArrayItem & objRS("DefaultVendor") & """, """
		strArrayItem = strArrayItem & objRS("DefaultTrainer") & """, """
		strArrayItem = strArrayItem & objRS("DefaultLocation") & """, """
		strArrayItem = strArrayItem & objRS("DefaultHours") & """, """
		strArrayItem = strArrayItem & objRS("DefaultLifeSpan") & """);"
		Response.Write(strArrayItem & vbNewLine)
		iCnt = iCnt + 1
		objRS.MoveNext
	wend
	objRS.Close
	Set objRS = Nothing
	DbGetCoursesJS = true
end function

解决方案

Irrespective of your question, Do you know that this implementation is susceptible of SQL Injection[^]?

I would suggest you to rather use Stored Procedure[^] or Parameterized Queries[^] in SQL.


Shouldn't your last line be end function?
Also, try using the number equivalents of the ado constants, and leave off the adCmdText.


这篇关于遇到错误!描述:变量未定义。编号:500。来源:Microsoft VBScript运行时错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆