Is there anything in C# that can be used as database Trigger -
i have erp database "a" has read permission, cant create trigger on table. made erp system (unknown program me ). have database "b" private application application work on both databases. want reflect a's changes(for insert/update/delete) instantly b. there functionality in c# can work trigger works in database???
you have few solutions, best 1 depends on kind of database have support.
generic solution, changes in database aren't allowed
if can't change master database , must work every kind of database have 1 option: polling.
you shouldn't check (so forget more or less instantly) save network traffic , it's better in in different ways insert/update/delete. can depends on how database structured, example:
insert: catch insert may check highest row id (assuming need monitor has integer column used key).
update: updates may check timestamp column (if it's present).
delete: may more tricky detect, first check count number of rows, if it's changed , no insert occured detected delete else subtract number of inserts.
generic solution, changes in database allowed
if can change original database can decrease network traffic (and complexity) using triggers on database side, when trigger fired put record in internal log table (just few columns: 1 change type, 1 affected table, 1 affected record).
you need poll on table (using simple query check if number of rows increased). because action (insert/update/delete) stored in table need switch on column execute proper action.
this has big disadvantage (in point of view): puts logic related application inside master database. may terrible or not depends on many many factors.
sql server/vendor specific
if you're application tied microsoft sql server can use sqldependency class track changes made. works ss think there may implementations other databases. disadvantage bee specific specific vendor (so if database change host...you'll have change code too).
from msdn:
sqldependency designed used in asp.net or middle-tier services there relatively small number of servers having dependencies active against database. not designed use in client applications, hundreds or thousands of client computers have sqldependency objects set single database server.
anyway if you're using sql server have other options, follow links in msdn documentation.
addendum: if need more fine control may check traceserver , object:altered (and friends) classes. more tied microsoft sql server should usable on more wide context (and may keep applications unaware of these things).
Comments
Post a Comment