Exporting XML file from a Stored Procedure using SSIS - ssis

have a Stored Procedure which has XML as Output and it shows xml output in SSMS. How should I generate an XML file to a specific location from this Stored Procedure using SSIS. I found a link which suggests using VB and script task to do this.Can this be done without using Script Task ? Also I tried following steps in this link :
How to export from SQL Server to XML
The Package fails at Execute SQL Task itself and gives the error [Execute SQL Task] Error: Executing the query "EXEC USP_PMAXML" failed with the following error: "Could not find stored procedure 'EXEC USP_PMAXML'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Thanks for your time and help.

A) The error you are receiving indicates it cannot find the stored procedure. You will want to verify
the stored procedure exists
The account access the stored procedure has execute permissions for it
The stored procedure exists in the default schema, probably dbo, for the account. {I've seen issues where procedures are created under user schemas [domain\user].USP_PMAXML }
The Connection Manager you are using is pointing the correct server and catalog (database).
B) If you would like to use an out of the box approach and avoid scripting, then remove your Execute SQL Task. Below I show an Execute SQL Task for reproduction purposes. It creates a stored proc that generates XML.
Add a Data Flow Task.
Within the Data Flow Task, add an OLE DB Source.
Configure your OLE DB Source to use the connection manager and the stored procedure we verified is correct from step 1
Assuming there should only be one file generated, add a Derived Column Transformation out of the OLE DB Source and inside of it, define the output file name which I assume is C:\ssisdata\so_xmlExtract.xml. I will further assume you rename the column as FileName. The exact value you would use is "C:\ssisdata\so_xmlExtract.xml" Note the doubling of slashes as we must escape the \ character as well as wrap with double quotes.
At this point, you're ready to use the Export Column Transformation. Examples Export Varbinary(max) column with ssis and
Using SSIS to extract a XML representation of table data to a file

Related

SSIS ETL execute MySQL Stored procedure on Destination Server

I am working on an SSIS ETL and I wanna know if there is a possibility to execute a MySQL Stored Procedure.
Here is what I want to do : From an SQL Server Database, I want to get Information by an ETL (SSIS) and send them to a MySQL Database (by a stored procedure)
Here is what I have done so far : I get my data from SQL Server Database and tranform them.
Here where I am stuck : I don't know how to execute an existing stored procedure on the MySQL Server Database (my destination)
Here is my ETL (DATA FLOW) diagram :
I also add an OLEDB provider on the server and add my destination source (MySQL Database) but I don't know what I need to do in my ETL to execute the stored procedure.
I can provide more information if necessary.
Thanks in advance
I am not sure if you mean that you want to execute a stored procedure by passing in every row in memory in SSIS that enters through your multicast. If that is the case, that may be possible with SSIS, but I have never done it.
why not just send the rows to two separate tables in MySQL from the multicast, then go back to the control flow tab and add two execute sql tasks, one for each stored procedure. Change each stored procedure to run on the tables instead of individual rows.
You would probably get a performance boost as well from switching to a set based operation instead of row by row.

How to return SQL statement that caused an exception from a stored procedure to SSIS

We have a SSIS package that calls a stored procedure through an EXECUTE SQL TASK component. The stored procedure contains a LOT of different pieces of sql code that gets build dynamically and then executed via exec strSQL within the stored procedure. The whole system is built that way and we cannot redesigned at this point. The problem is that when something fails within the stored procedure is hard to figure out from SSIS what SQL statement from the stored procedure caused the exception/failure. What we have right now and is working is the package onError event with code to read the System::ErrorDescription which is helpful to display the error in SSIS and then send an email with the error, this is working. What I'm looking for to add is to have a System Variable or some other way to display the actual SQL (the one that caused the exception within the stored procedure) in SSIS to I can include that in the email. Any ideas? Thanks.
I have a solution. Table variables are not roled back in a catch block and rollback statement.
So put the sql statements before they run into a table varaible with an nvarchar (max) datatype. Make sure your proc uses try catch blocks and transactions. In the catch block, perform a rollback if need be and then insert the contents of the table variable and a datetime to a logging table. NOw you have a record of exactly what queries were run. You can also create a separate table varaible to store the data you are attempting to insert or update if that is also an issue.
When you run a package by using F5 and a SQL statement fails you can check the execution results tab, but unfortunately this only shows the first line or two of your SQL statement.
Instead of running the package by using F5, run it using Crtl+F5. This will open a terminal window and run the package as though it was called from the command line. As each task runs it will output log information, if the task uses a SQL statement and it fails it will output the full SQL statement.
Ctrl+F5 is called 'Start Without Debugging' yet I always think it is a better to debug a package.

SSIS OLE DB Source using providers

I'm using a procedure that uses a table variable to fetch relevant data from my DB, and then returns whatever is stored in that table variable to my data flow.
My OLE DB Source is only designed to run the SQL command EXEC FetchData_prc.
It shows the required columns in the Source Editor, and it also lets me do mapping, preview and all of that.
YET, when running the package, it throws the error: [OLE DB Source [1]] Error: A rowset based on the SQL command was not returned by the OLE DB provider.
You may try to set nocount on on your stored procedure to prevent the server from returning the row count. This could be mistaken by SSIS as the returned result set. See this

SSIS dynamic source and destination tables

I have some requirements as explained below:
I need to have a SSIS data data flow task,which will accept the input parameters as
--SourceServer Connection String
--DestinationServer Connection String
--Source Table Name
--Destination Table Name
Then It should do the column mapping of source and destination tables dynamically at run time.
The source and destination tables schema would be same always.
I want to call this package by passing the above parameters from C#.net.
One main thing is here I will have to pass different sets of source and destination tables.
just answered this on a previous question. You cant loop through tables and dinamically map columns on your source and destinations components. You would need one set of Source -> Ddestination per table.
If that's not feasible, you may want to lokk at the Transfer SQL Server Objects Task
Create SSIS Packages parameters. Set web.config file for passing that parameters.
First you deploy the package in SQL Server.
Create one job for execute the package.
Create one sp using SQL Server.
& execute the job.
using sp_start_job.
I think it solve ur problem.

MySQL Stored Procedure that Evaluates Whether Another Procedure Runs or Not

I am writing a stored procedure that needs to execute a .sql source file. The MySQL stored procedure must run the .sql script and provide a return value based on whether the .sql file exists, if an error occurs or if it exists and executes without errors. Can anyone provide me with some direction on the proper syntax to use in my stored procedure to call the .sql file? Is it simply CALL myfile.sql?
Thanks,
Sid
There are no commands in MySQL language to read a .sql file.
The "source" keyword is an internal command of the MySQL command line.
If you want to execute one SQL command from a file, you can do the following:
1) read the file into a table, using the LOAD DATA INFILE command (but some security restrictions apply);
2) load the first record from that file into a variable;
3) create a prepared statement from the variable;
4) execute the prepared statement.
The above procedure is fraught with restrictions and problems, however.
The first and most notable one is that allowing execution of generic code is a security liability. The second one is that you will have little control on what you are executing.
If you really must, you could use MySQL Proxy (http://launchpad.net/mysql-proxy), which can perform the above operations with much more control and flexibility on each step.