Trigger will not export to Excel Spreadsheet

  • Hiya all, this is my first post here. I hope you can help me.

    I have a trigger attached to a table that will export data to an Excel spreadsheet when a record is inserted to that table. When I insert the record, I get the following error:

    The current transaction could not be exported to the remote provider. It has been rolled back.

    The script I am using is below:

    Insert into OpenDataSource

    (

    'Microsoft.Jet.OLEDB.4.0', 'Data Source=C:\ITTeam\Excel\Book1.xls;Extended Properties=Excel 8.0'

    )

    ...[Sheet1$]

    SELECT * FROM CUSTOMERS

    I think the script is OK because it works when:

    1. I execute the script from a SqlClient.SqlCommand object within a VB .Net application

    2. If I place the script in a stored procedure and execute it from a VB .Net application.

    Thanks in anticipation

    Rob

  • First, triggers are inside the transaction and putting something that needs external resources (send mail, openrowsource, etc.) is a bad idea. You are asking for lots of issues.

    Insert the row into a table and then periodically, even every minute, run an export with SSIS to throw this into your spreadsheet.

  • I would create a table that holds a flag.

    Have your trigger set the flag

    Set up a schedule job that runs every minute or so with a task that says

    IF EXISTS(SELECT 1 FROM dbo.FlagTable WHERE Flag=1)

    BEGIN

    UPDATE dbo.FlagTable SET Flag=1

    exec your query

    END

    The alternative is to have the trigger start your job but you need to put the check in place to detect if your job is running already. There is a system management view for this but its name escapes me.

  • Exporting to spreadsheet is "Death by SQL"... if someone opens it, BOOM! Process in SQL is dead... period.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • In MS Excel go to Data -> Import External Data -> New Database Query.

    Follow instructions in the wizard to create a query to your database.

    _____________
    Code for TallyGenerator

  • Hiya folks, thanks for your responses. So... does anybody know why the error

    The current transaction could not be exported to the remote provider. It has been rolled back.

    is occurring and how we can fix it? That would be a problem solved.

    Thanks

    Rob

  • As Steve said before, DO NOT USE TRIGGER !!!!!

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply