Now, after four pages of building up to it, we can start on the matter of MIRRORING WEB DATA.
I was lucky enough to obtain a brand new HP Kayak PC for £150 - a real bargain. The operating system is Microsoft Windows 2000 Server. At the moment it is sitting on my dining room table (a new toy you see - hehehehe) connected to my home LAN. The LAN has an ADSL connection to the World Wide Web.
For the development of the Mirroring technology, it was the 'other PC' - but it could perfectly well have been a server at any ISP in the world.
There are three steps to the Mirroring process:-
- Capturing details of the Updates to tables on the Main Server;
- Moving details of the Updates to the BackUp Server;
- Updating tables on the Backup Server.
First I needed a database table to store the details of the Updates. The structure is shown below
| Data Item Name | Data Item Type |
|---|---|
| connection_string | String Text |
| dataBaseRoot | String Text |
| end_trans | Logical (True/False or Yes/No) |
| original_unique_number | Number |
| program_name | String Text |
| send_done | Logical (True/False or Yes/No) |
| send_done_date_time | Date + Time |
| send_started_date_time | Date + Time |
| start_trans | Logical (True/False or Yes/No) |
| trans_block_ref | Number |
| trans_date_time | Date + Time |
| unique_number | Number |
| update_string | String Memo |
Next a file called datalog.asp it is shown below. There are three major functions in it. It is shown below :-
<%
'''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''
''' '''
''' '''
''' This file contains the routines for '''
''' recording the updates to data tables. '''
''' '''
''' '''
'''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''
DBConDATA = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & dataLogBaseRoot & "datalog.mdb"
''Response.Write DBConDATA
''Response.End
set ConDATA = Server.CreateObject("ADODB.Connection")
ConDATA.Open DBConDATA
cNowDateStr = "%D %b %Y %H:%N:%S"
cNow = UCase(fncFmtDate(Now, cNowDateStr))
lRecordIt = True
if InStr(UCase(Request.ServerVariables( "PATH_TRANSLATED" )), UCase("assistant")) > 0 then
lRecordIt = False
end if
if InStr(UCase(Request.ServerVariables( "PATH_TRANSLATED" )), UCase("show")) > 0 then
lRecordIt = False
end if
if InStr(UCase(Request.ServerVariables( "PATH_TRANSLATED" )), UCase("getdatalog")) > 0 then
lRecordIt = False
end if
if InStr(UCase(Request.ServerVariables( "PATH_TRANSLATED" )), UCase("confirmdatagot")) > 0 then
lRecordIt = False
end if
addStartDataTransaction()
Dim cTrans_block_ref
function addStartDataTransaction()
addStartDataTransaction = False
MinutesDiff = CLng((DateDiff("s",now,#1/1/2000#) * - 1))
RandomKey = (MinutesDiff * 100)
cTempUniqueStr = Request.ServerVariables( "PATH_TRANSLATED" ) & "-" & timer & "-" & RandomKey
''Response.Write cTempUniqueStr
if lRecordIt = True then
SQLStrDATA = "INSERT INTO datalog ("
SQLStrDATA = SQLStrDATA & "update_string, "
SQLStrDATA = SQLStrDATA & "trans_date_time, "
SQLStrDATA = SQLStrDATA & "program_name, "
SQLStrDATA = SQLStrDATA & "dataBaseRoot, "
SQLStrDATA = SQLStrDATA & "start_trans"
SQLStrDATA = SQLStrDATA & ") values ("
SQLStrDATA = SQLStrDATA & "'" & cTempUniqueStr & "', "
SQLStrDATA = SQLStrDATA & "#" & cNow & "#, "
SQLStrDATA = SQLStrDATA & "'" & Request.ServerVariables( "PATH_TRANSLATED" ) & "', "
SQLStrDATA = SQLStrDATA & "'" & dataBaseRoot & "', "
SQLStrDATA = SQLStrDATA & " " & "True" & " )"
''Response.Write SQLStrDATA
''Response.End
Set rsDATA = ConDATA.Execute( SQLStrDATA )
SQLStrDATA = "SELECT * FROM datalog WHERE update_string = '" & cTempUniqueStr & "'"
Set rsDATA = ConDATA.Execute( SQLStrDATA )
if rsDATA.EOF or rsDATA.BOF then
Response.Write "There has been a major DataLogging Error.<BR>The program has Terminated.<BR>SORRY"
Response.End
else
cTrans_block_ref = rsDATA("unique_number")
end if
SQLStrDATA = "UPDATE datalog SET trans_block_ref = unique_number WHERE update_string = '" & cTempUniqueStr & "'"
Set rsDATA = ConDATA.Execute( SQLStrDATA )
SQLStrDATA = "UPDATE datalog SET update_string = ' ' WHERE update_string = '" & cTempUniqueStr & "'"
Set rsDATA = ConDATA.Execute( SQLStrDATA )
end if
addStartDataTransaction = True
end function
function addDataTransaction(cADTUpdateStr, cADTConStr)
addDataTransaction = False
if lRecordIt = True then
cADTUS = Replace(cADTUpdateStr, "'", "''")
SQLStrDATA = "INSERT INTO datalog ("
SQLStrDATA = SQLStrDATA & "update_string, "
SQLStrDATA = SQLStrDATA & "trans_date_time, "
SQLStrDATA = SQLStrDATA & "program_name, "
SQLStrDATA = SQLStrDATA & "dataBaseRoot, "
SQLStrDATA = SQLStrDATA & "trans_block_ref, "
SQLStrDATA = SQLStrDATA & "connection_string"
SQLStrDATA = SQLStrDATA & ") values ("
SQLStrDATA = SQLStrDATA & "'" & cADTUS & "', "
SQLStrDATA = SQLStrDATA & "#" & cNow & "#, "
SQLStrDATA = SQLStrDATA & "'" & Request.ServerVariables( "PATH_TRANSLATED" ) & "', "
SQLStrDATA = SQLStrDATA & "'" & dataBaseRoot & "', "
SQLStrDATA = SQLStrDATA & " " & cTrans_block_ref & " , "
SQLStrDATA = SQLStrDATA & "'" & cADTConStr & "')"
''Response.Write SQLStrDATA
''Response.End
Set rsDATA = ConDATA.Execute( SQLStrDATA )
end if
addDataTransaction = True
end function
function addEndDataTransaction()
addEndDataTransaction = False
if lRecordIt = True then
SQLStrDATA = "INSERT INTO datalog ("
SQLStrDATA = SQLStrDATA & "update_string, "
SQLStrDATA = SQLStrDATA & "trans_date_time, "
SQLStrDATA = SQLStrDATA & "program_name, "
SQLStrDATA = SQLStrDATA & "dataBaseRoot, "
SQLStrDATA = SQLStrDATA & "trans_block_ref, "
SQLStrDATA = SQLStrDATA & "end_trans"
SQLStrDATA = SQLStrDATA & ") values ("
SQLStrDATA = SQLStrDATA & "'" & " " & "', "
SQLStrDATA = SQLStrDATA & "#" & cNow & "#, "
SQLStrDATA = SQLStrDATA & "'" & Request.ServerVariables( "PATH_TRANSLATED" ) & "', "
SQLStrDATA = SQLStrDATA & "'" & dataBaseRoot & "', "
SQLStrDATA = SQLStrDATA & " " & cTrans_block_ref & " , "
SQLStrDATA = SQLStrDATA & " " & "True" & " )"
''Response.Write SQLStrDATA
''Response.End
Set rsDATA = ConDATA.Execute( SQLStrDATA )
end if
addEndDataTransaction = True
end function
%>
It creates a 'Start' entry as soon as the file is opened.
All of the individual web pages have been modified to addDataTransaction() for each transaction that makes any addition, change or deletion to database tables.
AND TO
addDataTransaction() when it is about to successfully terminate.
You will recall that the part of the Web Page that adds new entries to database tables looks like.
SQLStr = "INSERT INTO name ("
SQLStr = SQLStr & "Title, "
SQLStr = SQLStr & "Forenames, "
SQLStr = SQLStr & "Surname, "
SQLStr = SQLStr & "Honours, "
SQLStr = SQLStr & "PublicInfo"
SQLStr = SQLStr & ") values ("
SQLStr = SQLStr & "'" & Replace(Request.Form("TITLE"), "'", "''") & "', "
SQLStr = SQLStr & "'" & Replace(Request.Form("FORENAMES"), "'", "''") & "', "
SQLStr = SQLStr & "'" & Replace(Request.Form("SURNAME"), "'", "''") & "', "
SQLStr = SQLStr & "'" & Replace(Request.Form("HONOURS"), "'", "''") & "', "
SQLStr = SQLStr & " " & lPublic & ")"
Set oRS = Con.Execute( SQLStr )
An SQL Command string is created and then it is Executed.
There are four major types of command used in my systems (the others are either not used or are not relevant to this subject) - they are :-
- INSERT INTO;
- DELETE;
- UPDATE;
- SELECT.
SQLStr = "INSERT INTO name ("
SQLStr = SQLStr & "Title, "
SQLStr = SQLStr & "Forenames, "
SQLStr = SQLStr & "Surname, "
SQLStr = SQLStr & "Honours, "
SQLStr = SQLStr & "PublicInfo"
SQLStr = SQLStr & ") values ("
SQLStr = SQLStr & "'" & Replace(Request.Form("TITLE"), "'", "''") & "', "
SQLStr = SQLStr & "'" & Replace(Request.Form("FORENAMES"), "'", "''") & "', "
SQLStr = SQLStr & "'" & Replace(Request.Form("SURNAME"), "'", "''") & "', "
SQLStr = SQLStr & "'" & Replace(Request.Form("HONOURS"), "'", "''") & "', "
SQLStr = SQLStr & " " & lPublic & ")"
dpReply = addDataTransaction(SQLStr, "Con")
Set oRS = Con.Execute( SQLStr )
That is the way in which the actual updates to the tables are captured.
The following line is added at the end of the script
dpReply = addEndDataTransaction()
That causes an 'End of Transaction' entry to be added.
It should be noted that only transactions that have a proper 'Start of Transaction' - and - 'End of Transaction' entry in the datalog table will be used to update the mirror copies of the database tables !!!
In the past, I have written such stories on one web page. One of the readers printed one out on paper - the paper was over fifty foot long. This time, Im using several pages to make it easier for readers to deal with. This page is just an Introduction to set the scene.
An index and links to the other pages is given below.