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


Extract ispac file from SSISDB


Extract ispac file from SSISDB

Author
Message
vaerge
vaerge
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 14
Hi -

I need to extract the .ispac file from the SSISDB. I can retrieve the stream with catalog.get_project sp. However, the file I end up with cannot be unzipped, giving an error message. My guess is that it is meta-data on the zip/ispac file that has a problem, because I can actually unzip it with Winrar, but not with any of those I (programmatically) need to unzip it with.

Below is the code for my stored procedure - please take a hard look at where something might go wrong. My own suspicion is in the BCP usage to turn the stream into a file.

Thanks,
Anders


USE [SSISDB]
GO

ALTER PROCEDURE [dbo].[spGetIspacFile]
@project VARCHAR(255) ,
@environmentFolder VARCHAR(50) ,
@ispacTempFolder VARCHAR(100) ,
@ispacFilePath VARCHAR(200) OUTPUT
AS
BEGIN
DECLARE @ispacFileName VARCHAR(200) = CONVERT(NVARCHAR(50), NEWID())
+ '.ispac'

SET @ispacFilePath = @ispacTempFolder + '\' + @ispacFileName


CREATE TABLE ##resultsTableVar
(
binaryProject VARBINARY(MAX)
)

INSERT ##resultsTableVar
( binaryProject
)
EXEC [SSISDB].[catalog].[get_project] @folder_name = @environmentFolder,
@project_name = @project

DECLARE @sqlCommand VARCHAR(500)

SET @sqlCommand = 'BCP "SELECT binaryProject FROM ##resultsTableVar" queryout "'
+ @ispacFilePath + '" -T -n -S"' + @@SERVERNAME + '"'

EXEC master.dbo.xp_cmdshell @sqlCommand

DROP TABLE ##resultsTableVar
END


vaerge
vaerge
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 14
I found the solution. Apparently, BCP is faulty, although it is uncertain exactly how - might be a header setting on the file that is not right, when it creates the file from the stream. So here is the solution, without using BCP. (thanks to this on Stackoverflow for leading to the solution):


USE [SSISDB]
GO

ALTER PROCEDURE [dbo].[spGetIspacFile]
@project VARCHAR(255) ,
@environmentFolder VARCHAR(50) ,
@ispacTempFolder VARCHAR(100) ,
@ispacFilePath VARCHAR(200) OUTPUT
AS
BEGIN
DECLARE @ispacFileName VARCHAR(200) = CONVERT(NVARCHAR(50), NEWID())
+ '.ispac'

SET @ispacFilePath = @ispacTempFolder + '\' + @ispacFileName


CREATE TABLE ##resultsTableVar
(
binaryProject VARBINARY(MAX)
)

INSERT ##resultsTableVar
( binaryProject
)
EXEC [SSISDB].[catalog].[get_project] @folder_name = @environmentFolder,
@project_name = @project


DECLARE @fileStream VARBINARY(MAX) ,
@objectToken INT

SELECT @fileStream = binaryProject
FROM ##resultsTableVar

EXEC sp_OACreate 'ADODB.Stream', @objectToken OUTPUT
EXEC sp_OASetProperty @objectToken, 'Type', 1
EXEC sp_OAMethod @objectToken, 'Open'
EXEC sp_OAMethod @objectToken, 'Write', NULL, @fileStream
EXEC sp_OAMethod @objectToken, 'SaveToFile', NULL, @ispacFilePath, 2
EXEC sp_OAMethod @objectToken, 'Close'
EXEC sp_OADestroy @objectToken

DROP TABLE ##resultsTableVar
END


bytehd
bytehd
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
Points: 19 Visits: 59
first try (from powershell):
Am able to write these out to an .ispac files and rename to .zip
but the contents are garbage

2nd try (SSMS)
your OACREATE method works, creates the ispac/zip file fine
but if im hitting a remore server
the powershell calls TSQL on the remote server which calls OACreate (local to it) and saves it the file on the remote server's disk



happycat59
happycat59
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4735 Visits: 3215

Below is the code for my stored procedure - please take a hard look at where something might go wrong. My own suspicion is in the BCP usage to turn the stream into a file.



I think that your issue with BCP is simply - it is the wrong tools for this task. BCP is intended to write data to a file on a row by row basis with a separator (e.g. CR/LF) between each row. What you need for this task is a method/tool that will write the individual bytes to a file with the extra separators. This is why the solution you found works.



Craig.Carpenter
Craig.Carpenter
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 63
Have you had success with this on SQL 2012 (11.0.5582) -- I am getting a transaction related error in the MS delivered sproc...

Msg 3915, Level 16, State 0, Procedure get_project, Line 105
Cannot use the ROLLBACK statement within an INSERT-EXEC statement.
bytehd
bytehd
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
Points: 19 Visits: 59
https://github.com/gwalkey/SQLTranscriptase

I have created an entire library of Powershell code to extract everything from SQL Server.

09_SSIS_Packages_from_SSISDB.ps1 creates ispac files using BCP just fine.

Cheers



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