SoFunction
Updated on 2025-03-02

Overview IE and SQL2k develop an XML chat program

Years of competition between different browsers have led to many tools that help developers complete tasks that were previously difficult to do. Now, in just a small piece of script, you can create an application that binds data to user controls, so that you can communicate with the server through an embedded proxy type control.

In Internet Explorer (IE), these include XML data islands and XMLHTTP objects, which are used to bind data to form elements, and XMLHTTP objects are used to create synchronous and asynchronous calls to the server without navigating to other pages within the current page. I will use these two easy-to-use features to create a simple chat application consisting of some ASP pages that act as UI, JavaScript that implements client functionality, and T-SQL that completes business logic in SQL Server 2000.

Clients and servers communicate using XML. After the web server receives a message block, the message block is appended to a timestamped MESSAGES table in SQL Server. Based on the predefined time interval, the client requests update information from the server, including the message list and the online user list that have been appended to the database since the last request from the server to the present.

The client will send a <action/> to the server via the XMLHTTP object. An action is either a request to refresh the message and user list, or a new message is sent. These actions are stored in a table called ACTIONS. The server will respond to the corresponding request or accept a new message and append it to the MESSAGES table.

When the server responds to a message request, it returns a list of all new messages after the last request. To track customer activity, I use an ACTIVITY table to contain the datetime of customer activity, and the customer's identity is saved in the table HANDLES, and the name of the table is very intuitive.

Here is the script for creating the table:

CREATE TABLE [dbo].[ACTIONS] (
    [action_id] [int] IDENTITY (1, 1) NOT NULL ,
    [action_name] [varchar] (50) NULL ,
    [action_descr] [varchar] (255) NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[ACTIVITY] (
    [handle_id] [int] NULL ,
    [action_time] [datetime] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[HANDLES] (
    [handle_id] [int] IDENTITY (1, 1) NOT NULL ,
    [handle] [nvarchar] (63) NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[MESSAGES] (
    [msg_id] [int] IDENTITY (1, 1) NOT NULL ,
    [message] [nvarchar] (255) NULL ,
    [action_id] [int] NULL ,
    [action_time] [datetime] NOT NULL
) ON [PRIMARY]

All data operations will be completed through stored procedures. All data interfaces are done through a generic COM that acts as a liaison for the Web server and SQL Server 2000. The COM object exposes a method I want to use RunSPReturnStream. The first parameter of this method is the name of the stored procedure, and the second parameter is the array of parameter arrays. Parameter array is a simple array in the following format: (paraName, paramType, paramLength, paramValue). paramType is one of the ADO Parameter Type enumerations. An ASP page is responsible for accepting actions and creating responses, which I call.

The chat page will contain a zone to display chat messages; this zone is a TABLE included in the DIV. This TABLE is bound to an XML Messages XML data island. Another area displays the current user; this area is also a TABLE contained in the DIV, which is bound to an XML data island of xmlUsers. There is also a TEXTAREA for users to enter messages.


--------------------------------------------------------------------------------
Author of this article: Phillip Perkins is the signatory of Ajilon Consulting. He has extensive experience, from machine control and client/server to intranet applications.