Using ASP and SQL to implement Web-based event Calendar _ database-related

Source: Internet
Author: User
This article describes how to build a web-based calendar while providing a process for creating Web sites for developers unfamiliar with active Server Pages (ASP), SQL, and ADO, as well as providing experienced developers with tips on Web site scalability.

With the development of Web applications, web-based calendars are becoming more and more popular, and web-based calendars are useful for displaying important events such as deadlines or scheduling, or showing who is on vacation. This article describes how to use IIS and the ASP in SQL Server to create a very simple web-based calendar and allow you to share your schedule with others or manage a group of people's calendars.

Build SQL Server Side

For Web calendars, we only need to save a text string that indicates the nature of the event on the server side, with a string up to 100 characters long. The design source code is as follows:

Calendar.sql
--Create a table
CREATE TABLE Schedule
(
Idschedule smallint Identity Primary key,
Dtdate smalldatetime NOT NULL,
Vcevent varchar (MB) NOT NULL
)
Go
--Stored procedures
CREATE PROCEDURE Getschedule (@nMonth tinyint, @nYear smallint)
As
Select Idschedule, convert (varchar, DATEPART (DD, dtdate)) ' Nday ', vcevent
From Schedule
where DatePart (yy, dtdate) = @nYear and datepart (mm, dtdate) = @nMonth
ORDER BY DATEPART (DD, dtdate)
Go
CREATE PROCEDURE addevent (@vcDate varchar), @vcEvent varchar (100))
As
Insert Schedule
Select @vcDate, @vcEvent
Go
CREATE PROCEDURE deleteevent (@idSchedule smallint)
As
Delete Schedule where idschedule = @idSchedule
Go


Designing ASP Clients

The following figure is the primary user interface for Web calendars, and users can see which events are scheduled. In addition, use the links at the bottom to flip around the calendar by month.





The implementation code for ASP is as follows:

Header.asp
<@ language= "VBSCRIPT"
EnableSessionState = False%>
<%
' Purpose: The table header includes files used to start all pages
' also include global functions
Option Explicit
Response.Buffer = True
Response.Expires = 0
Sub Doheader (strtitle)
%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>event Calendar-<%= strtitle%></title>
<body bgcolor= "white" link= "Blue" alink= "Blue" vlink= "Blue" >
<basefont face= "Verdana, Arial" >
<center><%
End Sub
function Getdataconnection ()
Dim oconn, strconn
Set oconn = Server.CreateObject ("ADODB. Connection ")
strconn = "PROVIDER=SQLOLEDB; Data SOURCE=ADSPM; Initial Catalog=teamweb; "
strconn = strconn && "User id=teamweb; Password=x "
oConn.Open strconn
Set getdataconnection = oconn
End Function
%>


With ADO, we can easily connect ASP pages to SQL databases. First we want to create a connection to the database. To get the recordset, we'll call the Execute method of the Connection object, pass in the text string of the command you want to execute, and then loop through the recordset once you have it. Header.asp contains functions to obtain data connections, which means that if the data source changes, we have only one location to edit the connection information (server, user, and password). Note that as a result, we must use the SET command at the end of the function to outgoing the new connection.

Optimize performance

ASP makes it easy to build Web pages, but if you want to build a site that can accommodate a large number of users, you need to think carefully about coding. The following article will provide readers with several ways to enhance Web calendar scalability, which can also be used to improve the performance of any ASP-based Web site.

1.SQL optimization

An easy way to improve site performance is to add an index to the date field in the Schedule table, so that it will find between the given dates, thus speeding up the getevents stored procedure.

For small sites, we can install SQL on the same server as IIS, and once site traffic starts to grow, we can move SQL to its own server, and when the traffic grows further, we can add multiple IIS servers that point to the same SQL Server. If the SQL server's traffic grows too much, you can split the data into different servers, we can assign odd months to one server, and even months to another server, of course, this requires modifying the getdataconnection in Header.asp, So that it provides you with a correct connection based on this month.

2.ASP optimization

The main optimization method for ASP interpretation will be to take advantage of caching pages so that they are not interpreted without each read. The easiest way to do this is to use ASP to application objects. To do this, you simply save the HTML to an application variable (such as calendar07-2000) that contains the name of the month and year. Then, when the Event calendar page is displayed, you first check to see if the calendar has been saved in the application variable, and if so, simply retrieve it, which can greatly speed up the query process for the site. The following code shows the work process:

<<do header>>
Showcalendar (Nmonth, Nyear)
<<do footer>>
Sub Showcalendar (Nmonth, Nyear)
If Application ("Calendar" && nmonth &&-"&& nyear" = "" Then
<<build calendar>>
Application ("Calendar" && nmonth && "-" && nyear) = <<Calendar>>
End If
Response.Write Application ("Calendar" && nmonth && "-" && nyear)
End Sub


Of course, when you change an event for a month on a events.asp page, you need to empty the application variables for that month to reflect the changes in those events.

Security

There are several ways to achieve security on this site. For  Intranet  sites, windows nt based validation is easiest to set up because your users will most likely have logged on to the network. You can have all users view the  Event Calendar  page, but only administrators can access the add/remove events  page.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.