Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,804 members, 7,817,334 topics. Date: Saturday, 04 May 2024 at 10:29 AM

Dynamicaly Update Database Recordset Across A Lan. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Dynamicaly Update Database Recordset Across A Lan. (1105 Views)

Update Database Via Wlan / Project:an Application To Make Calls Using LAN/INTRANET Network / Need Ur Contribution, Browse Based Application On A Lan (2) (3) (4)

(1) (Reply) (Go Down)

Dynamicaly Update Database Recordset Across A Lan. by tomX1(m): 7:05pm On Nov 19, 2007
Hi Gurus,
I've a little problem here.
I developed a database application using visual c++ and ADO (activex data object). The program works across a local area network (LAN) such that any system on the LAN running the program is able to update the database.
My problem however is how to inform all other connected systems that the database has been updated so that they can refresh their records.
Any sugestion will be welcomed.
(@smartk, na your answer I dey wait for o! Bros, I hail).
Re: Dynamicaly Update Database Recordset Across A Lan. by Kobojunkie: 9:09pm On Nov 19, 2007
Set up a timer to update the RecordSets at interval from the Database. You Can set the timer to repopulate your recordset every 30 minutes. You can also write a webservice and using ajax, you can connect to the database and check for changes and update if true.
Re: Dynamicaly Update Database Recordset Across A Lan. by tomX1(m): 10:59pm On Nov 19, 2007
Using Ajax is out of it since its not an online program.
As for the timer, I doubt that that will solve the problem. The software will run in an office where, say, 2 to 5 typists might be working over the LAN to input registration information of clients to the database from their own terminal. The program computes a heirarchy so any record created will definitely affect a lot of the existing records if they are ancestors of the new entry. New records will only be allowed when their ancestors are already in the database. The software works fine as a stand alone program but when on the LAN the update becomes a nasty problem.
If I'm to use a timer to refresh the recordset then the timer would probably have to fire every few second or so and I think this will create some performance issues.
Also the data entry is tightly controlled. Each entry is given a unique ID which is auto-generated and part of the ID is formed by taking a record count and incrementing by 1. If two client terminals are to read the record count from the database at almost the same time, they will both generate similar IDs and only one of the ID will be accepted and that will trigger a rejection to the entry from the other client. This will just continue to happen for almost all the entries.
Re: Dynamicaly Update Database Recordset Across A Lan. by Kobojunkie: 12:39am On Nov 20, 2007
@tomX:

Using Ajax is out of it since its not an online program.
As for the timer, I doubt that that will solve the problem. The software will run in an office where, say, 2 to 5 typists might be working over the LAN to input registration information of clients to the database from their own terminal. The program computes a heirarchy so any record created will definitely affect a lot of the existing records if they are ancestors of the new entry. New records will only be allowed when their ancestors are already in the database. The software works fine as a stand alone program but when on the LAN the update becomes a nasty problem.
If I'm to use a timer to refresh the recordset then the timer would probably have to fire every few second or so and I think this will create some performance issues.
Also the data entry is tightly controlled. Each entry is given a unique ID which is auto-generated and part of the ID is formed by taking a record count and incrementing by 1. If two client terminals are to read the record count from the database at almost the same time, they will both generate similar IDs and only one of the ID will be accepted and that will trigger a rejection to the entry from the other client. This will just continue to happen for almost all the entries.

If the code to generate the unique ID outside of the Database or a query?
Re: Dynamicaly Update Database Recordset Across A Lan. by tomX1(m): 4:36pm On Nov 20, 2007
@kobojunkie,
Thanks for replying.
The ID generation code is not part of a query. It's a function and it only parses through the database to see how many records already exist. It increments the count by 1 and append the result to a preformated string to get an ID. The ID column is a primary key. If two client systems parse the database after an entry, they will both probably end up generating the same ID and only one of them will be able to update the database.
The program uses a dsn-less connection and connects to the database as soon as the view class is initialised (OnInitialUpdate()). The connection type for the database is opened thus

m_pRS->Open(vNull,vNull,adOpenDynamic,adLockOptimistic,adCmdUnknown);



though I've tried using the pessimistic connection and it did not change much.
Re: Dynamicaly Update Database Recordset Across A Lan. by tomX1(m): 4:51pm On Nov 20, 2007
@kobojunkie,
Thanks for replying.
The ID generation code is not part of a query. It's a function and it only parses through the database to see how many records already exist. It increments the count by 1 and append the result to a preformated string to get an ID. The ID column is a primary key. If two client systems parse the database after an entry, they will both probably end up generating the same ID and only one of them will be able to update the database.
The program uses a dsn-less connection and connects to the database as soon as the view class is initialised (OnInitialUpdate()). The connection type for the database is opened thus

m_pRS->Open(vNull,vNull,adOpenDynamic,adLockOptimistic,adCmdUnknown);

m_pRS is the recordset pointer

though I've tried using the pessimistic connection and it did not change much.


The defination of the function that generates the ID looks like this:

void CRegistration::m_AddNewRecord()
{

UpdateData(TRUE);

m_pRS->MoveFirst();
int m_maxRecordCount = 0;
while(VARIANT_FALSE==m_pRS->adoEOF)
{
m_maxRecordCount++;
m_pRS->MoveNext();
}

m_strRegNum.Format("PMC-%d",m_maxRecordCount);
try
{
m_piadoRB->Update(&m_custRS);
//can we add a new record?
if(m_pRS->Supports(adAddNew))
{
//create a blank record and add the content from the custom recordset
m_piadoRB->AddNew(&m_custRS);
//Move to the last record
m_pRS2->MoveLast();
m_boolAdded = TRUE;
}
}
catch(_com_error &e)
{
//generate an error message
GenerateError(e.Error(),e.Description());
m_boolAdded = FALSE;
}

}



m_pRS is a _RecordSetPtr pointer.
m_piadoRB is a IADORecordBinding* pointer
m_custRS is a variable to the custom recordset that updates the records of the variable so i don't have to work directly with variant types.
Re: Dynamicaly Update Database Recordset Across A Lan. by kanirip: 5:03pm On Nov 20, 2007
I have some Ideas but I'm not sure if they apply to C++ , especially the Windows version.

Firstly I doubt you can do this without adding a lot of extra code to your app. If I was doing this
and I had already created a 'database App' and I needed to makje sure some sort of concurrency and
database/program synchronization was maintained ( which I deduce is what you are trying to do) then I
would create a seperate 'Maintainer' Thread.
This thread would check the database after every couple of seconds( in the background of course) for
changes in a recordset ( or table) and update the running program as necessary.
I think this would accomplish your task.

If you wanted to go astep further , you could create a fully distributed app and yo, I'm sure you don't wanna
hear all of this. Just see if you can do step 1, i fear its the only way!

And BTW, any Applications that uses Asynchronous communication is, theoretically, an AJAX application. wink

K
Re: Dynamicaly Update Database Recordset Across A Lan. by tomX1(m): 5:09pm On Nov 20, 2007
Thank for your sugestion @kanirip. I will give that a shot ank let you guys know the result.
Re: Dynamicaly Update Database Recordset Across A Lan. by Kobojunkie: 6:59am On Nov 21, 2007
Glad Kanirip gave you information there. I have a suggestion that may sound seem to be same as what he is saying to do. Wrap your ID generation code so that requests for new ID are queued. When a Typist saves data to the DB, the code sets a flag and then generates Id for that and then saves ( assuming this is the sequence). If the other typist tries to save data to the DB at that same time, with the flag already set to ON by the other process, the second request is queued and processed after the flag is set to OFF ( saving of previous file has been completed).

(1) (Reply)

C Programs / Need Help On Login Page / Learn HTML & CSS Coding With Ease!!

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 30
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.