Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Sql Server Programming

To get ADO event whenever a ROW is inserted


I do not have expertise in ADO, so before writing any code, I thought
of clarifying few facts. I want ADO to fire an event not just when a
ROW gets inserted by another application but when the inserted row
contains a specific value. If I take the table, given below as
example, I should get an event
when the following query succeeds
SELECT * FROM log_info_table WHERE LogMessage LIKE '%pppp123qqq%',

Example: log_info_table
LogType(int)             LogMessage(nvchar)
---------------------------------------------------------------------------
-----
   1                           Success ItemID: 'pppp123qqq'
   1                           Success ItemID: 'gggg678hhh'

As a first step, I wanted to get notified when ever someone inserts a
ROW using SQL manager; and this is irrespective of the inserted value.
I based my code on MS sample, and ran in to some problems; and hope
you can help me here.

Intension of my code was to receive notifications when ever a row gets
added to the table using 'SQL Manager'. To do this, I registered for
'RecordSet' events and also called RecordSet::Open() with table_name,
like RecordSet::Open( 'table_name', pConn, adOpenKeyset,
adLockReadOnly, adCmdTable).
When this line executed, I got WillMove, MoveComplete, ExecuteComplete
events and I kept the application running; and I inserted few rows in
to 'table_name' using SQL Manager and I did not get any Recordset
events. I was expecting at least any one of the RecordSet event to get
called.

For testing sake, to RecordSet::Open(), I passed a SQL query like this
RecordSet::Open('Select * from agent_action', pConn, adOpenKeyset,
adLockReadOnly, -1), and I got notifications.
This shows my event registration is working.
.
How to make my app get notification when a row gets inserted using SQL
manager?

Here is my code.

main()
{
 ADODB::_ConnectionPtr spConn(__uuidof(ADODB::Connection));
 ADODB::_RecordsetPtr spRS(__uuidof(ADODB::Recordset));

 SetConnectionEvents(spConn);
 spConn->Open(L"DSN=AccessTest", L"sa", L"sa", -1L);

 SetRSEvents(spRS);

 //spRS->Open(L"Select * from agent_action", spConn.GetInterfacePtr(),
ADODB::adLockReadOnly, ADODB::adLockOptimistic, -1);
 spRS->Open(L"agent_action", spConn.GetInterfacePtr(),
ADODB::adOpenKeyset, ADODB::adLockReadOnly, ADODB::adCmdTable);

 while(1)
 {
  Sleep(1000);
 }
 ......

}

Thanks
Ramesh
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc