Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Detect new record entered/updated in MS SQL

Detect new record entered/updated in MS SQL

Scheduled Pinned Locked Moved Database
csharpdatabasequestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vu Truong
    wrote on last edited by
    #1

    Hello, My application is required to monitor a database in MS SQL. Can I use C#/ADO.NET to develop the application that is to detect a new record entered or updated in MS SQL? I appreciate your helps.

    I 1 Reply Last reply
    0
    • V Vu Truong

      Hello, My application is required to monitor a database in MS SQL. Can I use C#/ADO.NET to develop the application that is to detect a new record entered or updated in MS SQL? I appreciate your helps.

      I Offline
      I Offline
      Ian Darling
      wrote on last edited by
      #2

      Vu Truong wrote: My application is required to monitor a database in MS SQL. Can I use C#/ADO.NET to develop the application that is to detect a new record entered or updated in MS SQL? Off the top of my head (I've never tried this, so YMMV), you could add a trigger to the database which on the relevant changes which calls into an extended stored procedure (or, if all you're doing is say, logging changes to a table back into another table for audit purposes, just use the trigger itself to update the log table) An extended stored procedure is an exported function from a DLL (C-style), so you'll probably need to expose your C# code in a manner that SQL Server can understand, or write a C++ wrapper that can interop with your code.


      Ian Darling "If we've learned anything from history, it's that those who feed trolls are condemned to repetitive conversations. Or something like that." - Eric Lippert

      C 1 Reply Last reply
      0
      • I Ian Darling

        Vu Truong wrote: My application is required to monitor a database in MS SQL. Can I use C#/ADO.NET to develop the application that is to detect a new record entered or updated in MS SQL? Off the top of my head (I've never tried this, so YMMV), you could add a trigger to the database which on the relevant changes which calls into an extended stored procedure (or, if all you're doing is say, logging changes to a table back into another table for audit purposes, just use the trigger itself to update the log table) An extended stored procedure is an exported function from a DLL (C-style), so you'll probably need to expose your C# code in a manner that SQL Server can understand, or write a C++ wrapper that can interop with your code.


        Ian Darling "If we've learned anything from history, it's that those who feed trolls are condemned to repetitive conversations. Or something like that." - Eric Lippert

        C Offline
        C Offline
        cmk
        wrote on last edited by
        #3

        Ian Darling wrote: Off the top of my head (I've never tried this, so YMMV), you could add a trigger to the database which on the relevant changes which calls into an extended stored procedure I recently did just that. I wrote several XP's to send messages to a specified server and port. Of course there is an issue of protocol for the message format. In general to write an XP you need the following : 1. Make sure you use the right srv header : i.e. place C:\PROGRAM FILES\MICROSOFT SQL SERVER\80\TOOLS\DEVTOOLS\INCLUDE before C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE in the list of include directories.

        #include <srv.h>    // MSSQL ODS header
        

        2. Make sure you link with the OpenDS library :

        #pragma  comment(lib, "opends60")    // MSSQL srv_*() functions
        

        3. Make sure all your XP's are compiled as C not C++. i.e. wrap with

        #ifdef __cplusplus
        extern "C" {
        #endif 
        ...
        #ifdef __cplusplus
        }
        #endif 
        

        if functions are in a cpp file. 4. Provide a __GetXpVersion() function in your library :

        __declspec(dllexport)  ULONG  __GetXpVersion( void )
        {
        	return(ODS_VERSION);
        }
        

        I ended up writing two sets of functions : CMKMSSQL_API SRVRETCODE xp_cmkInitSvcMsg ( SRV_PROC *SP ); CMKMSSQL_API SRVRETCODE xp_cmkTermSvcMsg ( SRV_PROC *SP ); CMKMSSQL_API SRVRETCODE xp_cmkSendSvcMsg ( SRV_PROC *SP ); CMKMSSQL_API SRVRETCODE xp_cmkBroadcastSvcMsg ( SRV_PROC *SP ); and CMKMSSQL_API SRVRETCODE xp_cmkInitGisMsg ( SRV_PROC *SP ); CMKMSSQL_API SRVRETCODE xp_cmkTermGisMsg ( SRV_PROC *SP ); CMKMSSQL_API SRVRETCODE xp_cmkSendGisMsg ( SRV_PROC *SP ); CMKMSSQL_API SRVRETCODE xp_cmkBroadcastGisMsg ( SRV_PROC *SP ); The *SvcMsg ones just send raw data to the specified server:port. The *GisMsg ones send protocol formated messages to one of my GIS servers. xp_cmkInit*Msg is called to create a connection to a specified server:port Usage : EXEC xp_cmkInitSvcMsg <@server> <@port> [@handle OUTPUT] The output handle is a long and is used to by the Term/Send functions. xp_cmkTerm*Msg is called to close a connection. Usage : EXEC xp_cmkTermSvcMsg <@handle> xp_cmkSend*Msg sends a blob of data using the connection associated with the specified handle. Usage : EXEC xp_cmkSendSvcMsg <@handle> <@msg> Because the message is sent using sock->Send( (byte*)srv_paramdata(SP, 2), srv_paramlen(SP, 2) ); The mess

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups