Click here to Skip to main content
14,032,238 members
Click here to Skip to main content
Add your own
alternative version


69 bookmarked
Posted 12 Nov 2003

ASP/SQL Server Based Chat program

, 12 Nov 2003
Rate this:
Please Sign up or sign in to vote.
Simple ASP/SQL Server Chat application

A sample chat window


This chat program was created simply because I didn’t want to buy one that had everything I wanted. This application is certainly not a complete application but it does take care of most general chat functions. I even included a few things some other applications don’t have such as smileys, language filters and room invitations.


Since I have a content management system that uses a domain_id identifier, I wanted to be able to offer the chat program to many of my clients without having to create a database for each one of them. So I added the domain_id identifier to allow many domains to use it without cross contamination. You will see that almost all functions will filter by this identifier.

The database is SQL Server. I tried to use an Access database but I had trouble getting Access to support multiple recordsets in a singe SQL call. Instead of describing the database in detail, I have included a script that will build the SQL database. The data_access.asp contains the username and password that is written into the SQL script. These can be changed as long as they are the same in both places. I use a separate config file when I integrate these. For the demo, I simply hard coded them.

Using the code


The code simply needs to be copied to any ASP virtual directory. No global.asa is needed. A database script is provided and just simply needs to be ran on the SQL Server with create database privileges.


In the install folder include/data_access.asp, simply replace the settings with your server info and you are all set. In my applications, this is an application variable. You may handle it however you wish.


default.htm is a sample of how you can integrate the chat into any page. Sessions are used to track user info and stuff like that but by changing the domain_id parameter, you can run as many simultaneous instances as you want.

Happy chatting!


  1. chat_rooms
    [id] [int] IDENTITY (1, 1) NOT NULL ,
    [room_name] [varchar] (150),
    [system_room] [int] NULL ,
    [private] [int] NULL ,
    [private_owner] [int] NULL ,
    [last_login] [datetime] NULL ,
    [domain_id] [int] NULL
  2. chat_users
    [id] [int] IDENTITY (1, 1) NOT NULL ,
    [user_name] [varchar] (50,
    [room_id] [int] NULL ,
    [date_in] [datetime] NULL ,
    [date_out] [datetime] NULL ,
    [user_ip] [varchar] (50),
    [active_time] [datetime] NULL ,
    [room_time] [datetime] NULL ,
    [domain_id] [int] NULL
  3. chat_user_invite
    [user_name] [varchar] (150),
    [room_id] [int] NULL ,
    [room_name] [varchar] (150),
    [private_room] [int] NULL ,
    [from_user] [varchar] (150),
    [domain_id] [int] NULL
  4. chat_msg
    [id] [int] IDENTITY (1, 1) NOT NULL ,
    [room_id] [int] NOT NULL ,
    [msg_ln] [varchar] (8000),
    [date_posted] [datetime] NULL ,
    [sortby] [int] NULL ,
    [sysmsg] [int] NULL
  5. chat_config
    [domain_id] [int] NULL ,
    [adm_uid] [varchar] (50)

This is the list of ASP files in the application

  1. admin_menu.asp

    Admin Menu is the menu screen for the administrator to use. It is basically a lobby and shows all the rooms that are in the system regardless if private. This screen has several options.

    1. Create a new room or system room. A system room is persistent and stays active until it is actually removed. A regular room stays until the last person logs out of it.
    2. Destroy rooms. If a room is removed with people in it, they are sent back to the lobby.
    3. Change the administrator user name.
    4. Link to another screen where users are listed. (users_view.asp)
    5. Link to another screen to set session options. (chat_user_options.asp)
  2. admin_view.asp

    Admin View is the chat window for the administrator. It is the same, but the language filter is turned off and the logging is turned off. It still uses the buttons.asp and the banner.asp.

  3. banner.asp

    Banner is used to display the room name, logout and return to lobby buttons.

  4. buttons.asp

    Buttons is the window used to type the message. It contains a content-editable DIV tag and a button. Some JavaScript is used to control the formatting buttons as well as some filtering for the query string.

  5. chat_user_options.asp

    This window is basically an HTML form to gather and display the session options for the user. I don’t bother storing these options in the database since I don’t store any user profiles. This could be altered and significantly enhanced.

  6. chatroom.asp

    This is the frameset for the banner, chat window and buttons. It contains a couple of script functions to check for session state and admin status.

  7. chatwindow.asp

    This is the actual message history window. It does nothing more than display the messages in formatted text as well as the actual smiley replacements and the language filters. It also checks for room validity in case it was deleted while you were in there.

  8. createroom.asp

    This is the backend file that actually does the database insert and validation of the room. It uses an array to construct the invite list. If a room already exists, it automatically appends a number to the end of the room. I could have confirmed with the user to accept this new room name but I opted to just create it.

  9. inframe.asp

    This file is the same as default.asp. It can be an include into a formatted page.

  10. invite_inc.asp

    This is an include file that simply runs the check to see if a user was invited into a room. It handles the response and redirects based on the invitation answer.

  11. lobby.asp

    The lobby is the first place you see when you create your login. It lists all the rooms and allows you to create a new room. (newroom.asp)

  12. login.asp

    This is simply the login page.

  13. loginuser.asp

    This is the backend code page to validate a login, or suggest a new login. It does all the admin validation and sets session variables once authenticated. This can be enhanced to include SQL validation or even Active directory validation.

  14. newroom.asp

    This displays the HTML form to gather the room name, and it allows users to type in other screen names to invite.

  15. toggleroom.asp

    This is a simple file to set a session variable to indicate a room was opened in the lobby, to view the users that are logged in.

  16. updateuseroptions.asp

    This is the backend code file to save the user options into the session. It redirects to chatroom.asp or lobby.asp.

  17. users_view.asp

    This admin screen shows all users logged in and gives the option to drop that user.

  18. updateadminoption.asp

    This file simply updates the database to change the admin username for the domain.

  19. mod_main.asp

    This is a global include in every ASP page. It contains the logintoroom and logoutofroom functions. It is where I put all superfluous functions. It also includes the data_access.asp which is the global data connection module.

  20. data_access.asp

    This is a module that I use in all my applications. It contains all the necessary functions to connect easily to a database using ADO. I use it in VB, ASP and even Access.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

flexluther06-Dec-08 7:05
memberflexluther06-Dec-08 7:05 
Questiondoubt in asp script Pin
karthi_salem22-Apr-08 0:02
memberkarthi_salem22-Apr-08 0:02 
GeneralRe: doubt in asp script Pin
cdidave22-Apr-08 1:57
membercdidave22-Apr-08 1:57 
Questionwhy not set Rs = Nothing ? Pin
wlnh4201-Jun-07 16:50
memberwlnh4201-Jun-07 16:50 
AnswerRe: why not set Rs = Nothing ? Pin
cdidave1-Jun-07 17:01
membercdidave1-Jun-07 17:01 
GeneralRe: why not set Rs = Nothing ? Pin
wlnh4201-Jun-07 17:19
memberwlnh4201-Jun-07 17:19 
AnswerRe: why not set Rs = Nothing ? Pin
flexluther6-Nov-08 5:31
memberflexluther6-Nov-08 5:31 
Generalhello testing Pin
saksham19-Jun-06 22:59
membersaksham19-Jun-06 22:59 
GeneralRe: hello testing Pin
saksham19-Jun-06 23:00
membersaksham19-Jun-06 23:00 
Generalref Pin
pkarthikmca30-Jan-06 22:53
memberpkarthikmca30-Jan-06 22:53 
GeneralInvite user in private room. Pin
Eddie Lee19-Mar-04 5:39
memberEddie Lee19-Mar-04 5:39 
GeneralRe: Invite user in private room. Pin
Eddie Lee19-Mar-04 5:50
memberEddie Lee19-Mar-04 5:50 
GeneralHi Pin
Anonymous9-Feb-04 1:15
memberAnonymous9-Feb-04 1:15 
GeneralRe: Hi Pin
sawant choudhary3-Feb-05 2:03
susssawant choudhary3-Feb-05 2:03 
GeneralRe: Hi Pin
Anonymous20-Apr-05 4:13
memberAnonymous20-Apr-05 4:13 
GeneralRe: Hi Pin
suheer15-Aug-05 1:20
membersuheer15-Aug-05 1:20 
GeneralRe: Hi Pin
sawant choudhary3-Feb-05 2:03
susssawant choudhary3-Feb-05 2:03 
GeneralConquerChat Pin
tommy skaue18-Nov-03 2:43
membertommy skaue18-Nov-03 2:43 
GeneralRe: ConquerChat Pin
cdidave18-Nov-03 4:54
membercdidave18-Nov-03 4:54 
GeneralAdministrator Options Pin
cdidave13-Nov-03 1:04
membercdidave13-Nov-03 1:04 
GeneralUser Options Pin
cdidave13-Nov-03 0:21
membercdidave13-Nov-03 0:21 
GeneralFeasibility flawed? Pin
dog_spawn13-Nov-03 5:42
memberdog_spawn13-Nov-03 5:42 
GeneralRe: Feasibility flawed? Pin
cdidave13-Nov-03 5:57
membercdidave13-Nov-03 5:57 
GeneralRe: Feasibility flawed? Pin
appwiz14-Nov-03 4:12
memberappwiz14-Nov-03 4:12 
GeneralRe: Feasibility flawed? Pin
Weiye Chen5-Jan-04 19:52
memberWeiye Chen5-Jan-04 19:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190419.4 | Last Updated 13 Nov 2003
Article Copyright 2003 by cdidave
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid