SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Trigger will not export to Excel Spreadsheet


Trigger will not export to Excel Spreadsheet

Author
Message
rclarkson
rclarkson
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 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
Steve Jones
Steve Jones
SSC Guru
SSC Guru (249K reputation)SSC Guru (249K reputation)SSC Guru (249K reputation)SSC Guru (249K reputation)SSC Guru (249K reputation)SSC Guru (249K reputation)SSC Guru (249K reputation)SSC Guru (249K reputation)

Group: Administrators
Points: 249565 Visits: 19809
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
My Blog: www.voiceofthedba.com
Dave Poole
Dave Poole
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26734 Visits: 3549
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
www.simple-talk.com
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (380K reputation)SSC Guru (380K reputation)SSC Guru (380K reputation)SSC Guru (380K reputation)SSC Guru (380K reputation)SSC Guru (380K reputation)SSC Guru (380K reputation)SSC Guru (380K reputation)

Group: General Forum Members
Points: 380904 Visits: 42984
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Sergiy
Sergiy
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44635 Visits: 12640
In MS Excel go to Data -> Import External Data -> New Database Query.

Follow instructions in the wizard to create a query to your database.
rclarkson
rclarkson
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 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
Loner
Loner
SSCrazy Eights
SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)

Group: General Forum Members
Points: 9550 Visits: 3364
As Steve said before, DO NOT USE TRIGGER !!!!!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search