Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Trigger will not export to Excel Spreadsheet Expand / Collapse
Author
Message
Posted Tuesday, January 8, 2008 8:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 10, 2008 4:09 AM
Points: 2, Visits: 6
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
Post #440096
Posted Tuesday, January 8, 2008 9:07 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 3:06 PM
Points: 33,169, Visits: 15,304
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.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #440113
Posted Tuesday, January 8, 2008 12:47 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 6:59 AM
Points: 2,899, Visits: 1,798
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.


LinkedIn Profile
Newbie on www.simple-talk.com
Post #440248
Posted Tuesday, January 8, 2008 6:45 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 3:51 PM
Points: 36,959, Visits: 31,469
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #440373
Posted Tuesday, January 8, 2008 7:41 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Monday, August 18, 2014 9:16 PM
Points: 4,576, Visits: 8,347
In MS Excel go to Data -> Import External Data -> New Database Query.

Follow instructions in the wizard to create a query to your database.
Post #440389
Posted Wednesday, January 9, 2008 7:39 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 10, 2008 4:09 AM
Points: 2, Visits: 6
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
Post #440658
Posted Wednesday, January 9, 2008 8:24 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, July 17, 2014 7:55 AM
Points: 2,805, Visits: 3,067
As Steve said before, DO NOT USE TRIGGER !!!!!
Post #440702
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse