Home Forums SQL Server 2008 T-SQL (SS2K8) trigger to call a program to write a text file onto a folder in the server RE: trigger to call a program to write a text file onto a folder in the server

  • eseeweb (4/30/2014)


    hi to all

    I had to agree that the reason for this trigger doesn't make sense. It is because we have 2 system.

    a) the first system can only generate data to a database

    b) the second system can only read in text file or csv file

    Both systems are 3rd party software that our company decide to use. So I end up were asked to write a trigger to call a program that a programmer wrote which did the following:

    a) get the inserted record

    b) write it to a text file

    c) delete the record in the database

    If i can do anything so that the insert record can be output to a text file, i will be very happy, because i don't think we need to delete the record. Once the record deleted from the database, we have no single trace. I would rather just export the record which only has 6 fields to a text file with delimiter using ","

    The program that wrote work fine if it just execute on a cmd line. It will read all records and delete the record. But when i use it in trigger it just look like it did nothing. It take a while for the record to show up when i use : select * from xyz and there is no text file created.

    I think either the user id (credential) don't allow it to create a text file and save it to a folder and/or like the post earlier said the insert is not committed yet and it cannot be delete?

    I am in search of a trigger script that can trigger after insert and export the inserted record to a text file. It seems that it can be done but i am very new to trigger. Any sample will be greatly appreciated.

    thx, Ted.

    You are already using command shell. Why not just use that to do your work, then you don't need this extra application at all. Or if CLR is an option at your shop that would be another option.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/