Beruflich Dokumente
Kultur Dokumente
Response Object
The ASP Response object is used to send output to the user from the server. Its collections,
properties, and methods are described below:
Collections
Collection Description
Cookies Sets a cookie value. If the cookie does not exist, it will be created, and take the
value that is specified
Properties
Property Description
Buffer Specifies whether to buffer the page output or not
CacheControl Sets whether a proxy server can cache the output generated by ASP or
not
Charset Appends the name of a character-set to the content-type header in the
Response object
ContentType Sets the HTTP content type for the Response object
Expires Sets how long (in minutes) a page will be cached on a browser before it
expires
ExpiresAbsolute Sets a date and time when a page cached on a browser will expire
IsClientConnected Indicates if the client has disconnected from the server
Pics Appends a value to the PICS label response header
Status Specifies the value of the status line returned by the server
Methods
Method Description
AddHeader Adds a new HTTP header and a value to the HTTP response
AppendToLog Adds a string to the end of the server log entry
BinaryWrite Writes data directly to the output without any character conversion
Clear Clears any buffered HTML output
End Stops processing a script, and returns the current result
Flush Sends buffered HTML output immediately
Redirect Redirects the user to a different URL
Write Writes a specified string to the output
Request Object
When a browser asks for a page from a server, it is called a request. The ASP Request object is
used to get information from the user. Its collections, properties, and methods are described
below:
Collections
Collection Description
ClientCertificate Contains all the field values stored in the client certificate
Cookies Contains all the cookie values sent in a HTTP request
Form Contains all the form (input) values from a form that uses the post
method
QueryString Contains all the variable values in a HTTP query string
ServerVariables Contains all the server variable values
Properties
Property Description
TotalBytes Returns the total number of bytes the client sent in the body of the
request
Methods
Method Description
BinaryRead Retrieves the data sent to the server from the client as part of a post request and
stores it in a safe array
Application Object
The Application object is used to store and access variables from any page, just like the Session
object. The difference is that ALL users share one Application object, while with Sessions there is
one Session object for EACH user.
Collections
Collection Description
Contents Contains all the items appended to the application through a script
command
StaticObjects Contains all the objects appended to the application with the HTML
<object> tag
Methods
Method Description
Contents.Remove Deletes an item from the Contents collection
Contents.RemoveAll() Deletes all items from the Contents collection
Lock Prevents other users from modifying the variables in the Application
object
Unlock Enables other users to modify the variables in the Application object
(after it has been locked using the Lock method)
Events
Event Description
Application_OnEnd Occurs when all user sessions are over, and the application ends
Application_OnStart Occurs before the first new session is created (when the Application object is
first referenced)
Session Object
The Session object is used to store information about, or change settings for a user session.
Variables stored in the Session object hold information about one single user, and are available to
all pages in one application. The server creates a new Session object for each new user, and
destroys the Session object when the session expires.
Collections
Collection Description
Contents Contains all the items appended to the session through a script command
StaticObjects Contains all the objects appended to the session with the HTML <object> tag
Properties
Property Description
CodePage Specifies the character set that will be used when displaying dynamic content
LCID Sets or returns an integer that specifies a location or region. Contents like date,
time, and currency will be displayed according to that location or region
SessionID Returns a unique id for each user. The unique id is generated by the server
Timeout Sets or returns the timeout period (in minutes) for the Session object in this
application
Methods
Method Description
Abandon Destroys a user session
Contents.Remove Deletes an item from the Contents collection
Contents.RemoveAll() Deletes all items from the Contents collection
Events
Event Description
Session_OnEnd Occurs when a session ends
Session_OnStart Occurs when a session starts
Server Object
The ASP Server object is used to access properties and methods on the server. Its properties and
methods are described below:
Properties
Property Description
ScriptTimeout Sets or returns the maximum number of seconds a script can run before
it is terminated
Methods
Method Description
CreateObject Creates an instance of an object
Execute Executes an ASP file from inside another ASP file
GetLastError() Returns an ASPError object that describes the error condition that
occurred
HTMLEncode Applies HTML encoding to a specified string
MapPath Maps a specified path to a physical path
Transfer Sends (transfers) all the information created in one ASP file to a second
ASP file
URLEncode Applies URL encoding rules to a specified string
Property Description
ASPCode Returns an error code generated by IIS
ASPDescription Returns a detailed description of the error (if the error is ASP-related)
Category Returns the source of the error (was the error generated by ASP? By a scripting
language? By an object?)
Column Returns the column position within the file that generated the error
Description Returns a short description of the error
File Returns the name of the ASP file that generated the error
Line Returns the line number where the error was detected
Number Returns the standard COM error code for the error
Source Returns the actual source code of the line where the error occurred
ObjectContext
The ObjectContext object is used to control Active Server Pages transactions, which are managed
by the Microsoft Transaction Server (MTS). You may either complete (commit) or abort a
transaction.
The @Transaction directive must be on the first line of the .asp file in order to use this object (see
code examples). The @Transaction directive causes a transaction to run to completion unless an
abort occurs.
Methods
Method Description
SetAbort Declares that a transaction has not been completed and resources should not
be updated.
SetComplete Declares that the transaction has been completed and resources can be
updated.
Events
Event Description
OnTransactionAbort Occurs when a transaction has been aborted for some kind of processing
error. The signal of this event will run a handler script in the same file, if it
exists.
OnTransactionComplete Occurs when a transaction has been successfully completed. The signal of
this event will run a handler script in the same file, if it exists.
COM
Component Object Model (COM) provides the fundamental ability for multiple applications or
software components to cooperate and communicate with one another. It doesn't matter in what
language the components were written or who programmed them. It doesn't even matter if the
components are running on different computers or different operating systems. COM and a similar
technology called DCOM provide an elegant way for everything to work together. Used in a
network with a directory and additional support, COM becomes the Distributed Component Object
Model (DCOM).
The COM defines a set of standards that all objects (commonly referred to as component) must
follow. These standards are what enable an application to utilize objects without knowing the
details of the object itself. It is the principles of COM that enable Visual Basic programs to use
ActiveX controls (objects) simply by adding the controls to the Toolbox.
Under the COM method, objects (software components) can be reused and expanded upon while
still providing the backward compatibility with applications that have been programmed to use
previous versions.
Application doesn’t initially interact directly with an object (OCX). It goes through COM first. And
COM gives App (client) an interface pointer by which it can communicate with object. All server
objects have an IUnknown interface. IUnknown enables the client to do two things and two things
only. To partially control the lifetime of an object and to invoke the object’s QueryInterface
function. The QueryInterface function enables a client to ask an object if it supports the function
that it desires.
Interfaces are not identified by COM using names – names are simply for programming
convenience. COM uses Globally Unique Identifiers (GUIDs) exclusively to reference interfaces.
Locator services, which are part of the COM library, are used by COM to determine from the class
identifier which server object implements that class and where on the system the object can be
located. A catalog of all available GUIDs on a system can be found in the System Registry. GUIDs
are 128-bit integers that are used to identify every interface and every object class.
Reference counting is a way for a server object to keep track of how many clients are currently
using it.
Atomicity: The atomicity property identifies that the transaction is either fully completed, or not
at all. If for any reason an error occurs and the transaction is unable to complete all its tasks, the
system is returned to the state it was in before the transaction even started.
Consistency: A transaction enforces consistency in the system’s integrity by ensuring that at the
end of any transaction the system is in a valid state.
Isolation: Transactions are performed in isolation, which makes them appear to be the only
action that the system is executing at a given time.
Durability: Durability means that once a transaction has been successfully completed, all of the
changes it made to the system are permanent.
COM+
COM+ is an extension of Component Object Model (COM), Microsoft's strategic building block
approach for developing application programs. COM+ is both an object-oriented programming
architecture and a set of operating system services. It adds to COM a new set of system services
for application components while they are running, such as notifying them of significant events or
ensuring they are authorized to run. COM+ is intended to provide a model that makes it relatively
easy to create business applications that work well with the Microsoft Transaction Server (MTS) in
a Windows NT or subsequent system.
COM+ is the basic COM and a set of additional services like Self describing, Transactions, Queued
Components (QC), Security, Loosely Coupled Events (LCE), Just In Time Activation (JITA), Basic
Interception Services, Object Pooling, Deployment and Administration.
Serialized: - Data read by a current transaction cannot be changed by another transaction until
the current transaction finishes. No new data can be inserted that would affect the current
transaction. This is the safest isolation level and is the default.
Read Committed: - A transaction cannot read data that is being modified by another transaction
that has not committed. This is the default isolation level in Microsoft SQL Server.
Read Uncommitted: - A transaction can read any data, even if it is being modified by another
transaction. This is the least safe isolation level but allows the highest concurrency.
Any: - Any isolation level is supported. This setting is most commonly used by downstream
components to avoid conflicts. This setting is useful because any downstream component must be
configured with an isolation level that is equal to or less than the isolation level of its immediate
upstream component. Therefore, a downstream component that has its isolation level configured
as Any always uses the same isolation level that its immediate upstream component uses. If the
root object in a transaction has its isolation level configured to Any, its isolation level becomes
Serialized.
Note: If a downstream component is configured with a higher isolation level than an upstream
component and attempts to enlist in a transaction, an error results and the transaction aborts.
ActiveX
ActiveX is the name Microsoft has given to a set of “strategic” object-oriented programming
technologies and tools. The main thing you create when writing a program to run in the ActiveX
environment is a component, a self-sufficient program that can be run anywhere in your ActiveX
network (currently a network consisting of Windows and Macintosh systems). This component is
known as an ActiveX control.
OCX stands for “Object Linking and Embedding control”. Object Linking and Embedding (OLE) was
Microsoft’s program technology for supporting compound documents such as the Windows
desktop. The Component Object Model now takes in OLE as part of a larger concept. One of the
main advantages of a component is that it can be re-used by many applications (referred to as
component containers).
Aside from ActiveX control projects, VB also includes several other project types that contain the
ActiveX Label. There are ActiveX EXE, ActiveX DLL, ActiveX Document EXE, and ActiveX
Document DLL. All are based on COM.
ActiveX EXE: -
ActiveX EXEs are used to create out-of-process components. In-process components are those
that run in the same address space of an application (also called a client). In-process components
can be thought of as a part of the application itself, even though they might actually exist in a
separate file or library. For example, if your VB program calls a function that Exists in Dynamic
Link Library (DLL), that function is linked to your application when the application is executed. It
becomes a part of the application (its client) and runs in the same address space, thus it is an In-
process component.
Out-of-process components, on the other hand, do not run in the same address space of their
client but instead run in their own address space. An application (a client) can use out-of-process
components the same way they use in-process components. However, out-of-process components
offer an important benefit. Since they run in their own address space, the code for the out-of-
process component can execute simultaneously with its client. Therefore, a client can tell an out-
of-process component to do something without having to wait for it to finish. When the
components task is done, it can notify its client by using asynchronous notification, a way of
passing messages back to the client.
When deciding whether to create a component as in-process or out-of-process, speed and the use
of system resources are the major considerations. Since In-process components exist in the same
memory space as their client, they are more efficient than out-of-process components. However,
more than one client can use out-of-process components simultaneously, cutting down on the
amount of system resources that are used.
ActiveX DLL
ActiveX DLLs differ from ActiveX EXEs in that they are in-process components instead of out-of-
process components. When a client application asks as in-process component to perform a task,
control of the program is given to the component. The client application has to wait until the
component is done performing the task before it can continue with its own processing.
Private: Code outside the DLL/EXE cannot create this object type. Other classes in the DLL/EXE
can use this type of class as a helper but the main program cannot use it.
PublicNotCreatable: The main program can use this type of class but cannot create new
instances using the New keyword or with CreateObject. In this case, you need to provide some
method within the other classes to create the new object and return it to the main program.
SingleUse: The main program can create the object. Every time you create a new object, the
system makes a new ActiveX EXE instance to service the object you created. Among other things,
if the EXE contains global variables then different objects you create get different copies of the
variables. This option is allowed for ActiveX EXEs only.
GlobalSingleUse: Similar to SingleUse except you can invoke the properties and methods of the
class as if they were simple global functions. This option is allowed for ActiveX EXEs only.
MultiUse: The main program can create the object. When it does, the system makes an ActiveX
DLL/EXE component to handle the object. If you make other objects, the system uses the same
ActiveX DLL/EXE component to handle them. This can be a little confusing depending on whether
you are building a DLL or EXE and whether an EXE is running on different computers.
If you build an ActiveX DLL, all programs run the DLL code in their own address spaces. That
means different objects created in the same program will share the same component server so
they could share global variables defined in the DLL. However, if the objects are all freed at the
same time, the component server will shut down so any global values will be lost.
GlobalMultiUse: This is similar to MultiUse except the main program can reference methods and
properties as if they were globally declared. When the program invokes one of the methods using
this global syntax, it creates an instance of the class to use its methods. It continues to use that
instance whenever it needs to execute a global method.
If you explicitly create other instances of the class, you get new object not the global one. As far
as I know, there is no way to get a direct reference to the global object instance.
This all seems pretty confusing so I would avoid using GlobalMultiUse and GlobalSingleUse. They
let you use a syntax that is more similar to that used by DLLs built in C++ and other languages
and that's probably why Microsoft implemented these. They hide the fact that there is an
underlying class object, however, so they increase your chances for confusion.
It is a common misconception that any codes using the CreateObject function instead of Set =
New is using late binding. This is not the case. The type declaration of the object variable
determines whether it is late or early bound, as in the following:
Dim A As Foo
Dim B As Foo
Dim C As Object
Dim D As Object
Most of us think that we were declaring x as a "Project1.Class1" class. This is wrong. In this line
of code x is declared as the _Class1 interface defined in the Project1 Type library (the underscore
is hidden by the kindness of the VB team). Note that in the above line of code you have not made
any assumption regarding what object will provide an implementation of the Project1.Class1
interface. It happens you write then:
One thing to stress: these 2 lines of codes are totally equivalent regarding early or late binding. If
you want to late-bind to the Project1.Class1 interface you should have written:
Dim x as Object ' read Object as Dispatch
The confusion arises from the fact that VB hides you from most of the details of interface and
classes definition.
- In the line [Dim x as Project1.Class1] Project1.Class1 is an interface indentifier (IID)
- In the line [Set x = New Project1.Class1] Project1.Class1 is a class identifier (CLSID)
- In the line [Set x = CreateObject("Project1.Class1")] "Project1.Class1" is the ProgId of the
class; the ProgId is the human-readable name of the class that is mapped to the CLSID. This
mapping is stored in the registry when you register your COM component (e.g. running
regsvr32.exe if the component is a DLL). If you create an object via the New keyword the CLSID
is read from the referenced component type library at build time and hard coded in your
component. If you use CreateObject VB queries the registry at run-time then map the ProgId to
the CLSID (The CLSID is what you have to pass to the COM run-time when you ask it to create an
object). As you may know you can even write:
In this case [Project1.Class1] is a class identifier. You are asking VB to create the Project1.Class1
class, ask to the object its default interface and place it into the x variable.
Q - What is an Enum?
A - Enum allows you to define a set of long integer constants that are global. If you have ever
wanted constants in a class module to be accessible to the client application, you now have the
capability with the Enum key word.
Example:
For example, if the Enum taskPriority was created in an ActiveX component, a reference to the
component could be set in a test application. This test application could then include the following
code:
RDO will connect remotely to almost any data source, but it doesn't handle local databases well,
performance wise. It is an easy interface to the MS ODBC API.
ADO is simpler and more efficient in resources than the above. It will access local and remote
databases, as well as files, and email programs like Exchange. It is also used in ASP.
RDO still has a strict hierarchy of objects you must go through to get results, execute stored
procedure, update data, etc. Starting with an Environment; then the connection; then the
recordset. It allows connecting to network databases a lot easier than trying to get DAO to do it.
And it was faster for that stuff than DAO. However, with ADO, you are no longer forced to create
"parent" objects in order to get to what you want - the data. It is streamlined for network
database access (SQL server, oracle, db2 etc). It allows connecting to many more databases (or
data "stores" - like MS Exchange, ADSI, Excel, and more).
ADO recordsets usually have THREE copies of the recordset in memory, whereas RDO only had
one. Why three? One that represents the database's copy of the records (the original), one with
which you are currently working (the only one you see), and another that represents the state of
those records the instant they were returned (which could be different from both your working
version and the data that's in the database). What are these for? They are used to determine the
validity of the data you're trying to update.
RDO speaks directly to the ODBC engine, while ADO speaks to an ActiveX/OLEObject server that
speaks to the ODBC engine.
ADO provides application level interface to data providers such as MS-SQL or Access. ADO uses
the set of interfaces provided by OLEDB to communicate with the MS SQL. OLEDB is a system-
level interface.
Microsoft is gradually replacing the ODBC standard with OLE DB. The problem with ODBC is that it
was developed with the narrow purpose of working with database that supports SQL Language.
OLE DB, on the other hand, was designed to works with a much wider range of Data sources such
as MS exchange, MS Index server and ADSI.
Example:
Dim d as integer
On error goto Errorhandler
d = 1/0
Exit sub
Errorhandler:
On error goto errorhandler2 'ineffective
d = 1/0
Exit sub
Errorhandler2:
Debug.print "You'll never get here"
End sub
No Compatibility
With this setting, new class ID’s, new interface ID’s and a new type library ID will be generated by
VB each time the ActiveX component project is compiled. This will cause any compiled client
components to fail (with error 429!) and report a missing reference to the 'VB ActiveX Test
Component' when a client project is loaded in the VB IDE.
TIP: Use this setting to compile the initial release of a component to other developers.
Project Compatibility
With this setting, VB will generate new interface ID’s for classes whose interfaces have changed,
but will not change the class ID’s or the type library ID. This will still cause any compiled client
components to fail (with error 429!) but will not report a missing reference to the 'VB ActiveX Test
Component' when a client project is loaded in the VB IDE. Recompilation of client components will
restore them to working order again.
TIP: Use this setting during the initial development and testing of a component within the IDE
and before the component is released to other developers.
Binary Compatibility
VB makes it possible to extend an existing class or interface by adding new methods and
properties etc. and yet still retain binary compatibility. It can do this, because it silently creates a
new interface ID for the extended interface and adds registration code to register the original
interface ID but with a new Forward key containing the value of this new interface ID. COM will
then substitute calls having the old ID with the new ID and hence applications built against the
old interface will continue to work (assuming the inner workings of the component remain
backward compatible!).
With this setting, VB will not change any of the existing class, interface or type library ID’s,
however in order that it can do so, VB requires the project to specify an existing compiled version
that it can compare against to ensure that existing interfaces have not been broken.
TIP: Use this setting following the release of a component to other developers.
When you decide to issue a new version of an MTS component you should take care of its
compatibility with the previous version. There are three types of changes you could make:
1) You change only internal code of a component, keeping the interface that the component
provides untouched.
2) You only add a member(s) (method, property, enum etc.) to the interface, but leave
declaration of previously declared members quite the same.
3) You decided to revise the interface members and some of them are changed or even removed.
Thus, if you're building a component in VB it's strongly recommended to set Version Compatibility
of the project to Binary Compatibility mode. In this case VB will track the changes of the
interface(s) and will notify you if you make changes of type (3), but not 2!
To install a new version into MTS you should do the following: For changes of type (1) you can
simply overwrite the older DLL with the newer one. The remote clients that had the client export
registered need no intervention, but with both (2) and (3) types of changes you should
completely reinstall the component (i.e. remove it from MTS and then install it back), you then
need to re-export the package and have the remote clients run the client installation again
(remove the old one before from Control Panel/Install remove applications). Don't forget to shut
the component's package down to unlock components' DLLs. It's possible to shut a package down
remotely and perform other administration operations "programmatically".