经典ASP测试,如果服务器可以创建对象

时间:2014-01-23 15:38:14

标签: asp-classic

使用此代码:

Dim xmlDOM
Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")    

如何测试CreateObject函数是否成功?

1 个答案:

答案 0 :(得分:4)

如果它不起作用,您可能会收到错误消息。否则,您可以使用以下代码:

Dim xmlDOM
'dont fail on error'
On Error Resume Next
Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
On Error GoTo 0 'turn error handling off again'

If Not xmlDOM Is Nothing Then
   'not null: it worked'
Else
   'xmlDOM is nothing.  It was not able to create the object. ' 
   'Check create permissions in COM+'
End If
相关问题