January 8, 2008 at 8:43 am
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
January 8, 2008 at 9:07 am
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.
January 8, 2008 at 12:47 pm
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.
January 8, 2008 at 6:45 pm
Exporting to spreadsheet is "Death by SQL"... if someone opens it, BOOM! Process in SQL is dead... period.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 8, 2008 at 7:41 pm
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
January 9, 2008 at 7:39 am
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
January 9, 2008 at 8:24 am
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