views:

400

answers:

3

according to

http://msdn.microsoft.com/en-us/library/ms524620.aspx

you should use server.createObject

If you are already familiar with VBScript or JScript, note that you do not use the scripting language's function for creating a new object instance (CreateObject in VBScript or New in JScript). You must use the ASP Server.CreateObject method; otherwise, ASP cannot track your use of the object in your scripts.

but some other folks think that server.createObject implies an overhead that most times could be avoided

http://classicasp.aspfaq.com/components/should-i-use-createobject-or-server-createobject.html

CreateObject has less overhead than Server.CreateObject, because the latter uses MTS — causing significant overhead.

You will also suffer performance hits when the component encounters errors, because with Server.CreateObject, these errors are written to the event log (which, admittedly, can be useful during debugging).

or

http://www.4guysfromrolla.com/webtech/043099-1.shtml

This can become significant if you are writing a component that deals with transactions, as it would be a good safety net to pass it through MTS, because you will be using MTS commands. However, if you are not using MTS, you could create processor and memory over head by passing it through Server.CreateObject. This makes it a better idea to use CreateObject, because it goes straight through.

so if I'm not using mts and need no access to the builtins asp's objects (like set d = createObject("scripting.dictionary") ) is it ok to just forget about the server.createObject and go with createobject ) ???

thanks a lot...

+1  A: 

In short, yes its fine. Just as Ryna S says if you read the whole of the last article:

"hope you understand the difference now, and when to use the two."

The situation you describe would be a good time just just use CreateObject rather than Server.CreateObject.

Unltimately it will not make that much of a difference unless you really are trying to squeeze every last ounce out of a server. Should be plenty fast enough either way.

Pete Duncanson
+2  A: 

Those articles you are quoting are somewhat out-of-date. Since IIS 5 and COM+ on Windows 2000 and above using the straight CreateObject is pretty much the same as using Server.CreateObject.

The MTS/COM+ behaviour of either CreateObject or Server.CreateObject is now the same, this in part due to the fact that ASP itself runs as a COM+ application. You can specify that the ASP page starts a transaction and then using CreateObject any object implementing IObjectContext will be invited to join the transaction etc.

The only real difference I know of is a legacy thing where a COM object being created may have OnStartPage and a OnEndPage method. Using Server.CreateObject these methods are called when the object is created and just before the object is released. This doesn't happen with CreateObject.

AnthonyWJones
Anthony you are a pool of ASP knowledge, where do you keep pulling this stuff from? Impressive as usual :)
Pete Duncanson
A: 

The advantage of using createobject is that one can either test, or reuse libaries when using plain cscript.exe. Just strip the <% %> tags.

Joost Moesker