dbTalk Databases Forums  

Executing a DTS Form Store Proc & Changing the connection

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Executing a DTS Form Store Proc & Changing the connection in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
WhiskRomeo
 
Posts: n/a

Default Executing a DTS Form Store Proc & Changing the connection - 06-12-2004 , 08:51 PM






The below SP (thanks to Database Journal (but simplified)) executes my DTS.

However, I need to modify one of the connections (XLS file path) before execution.
Thus, I would need to add another parameter @Path for example.

But how do I change the connection information within the Stored Procedure. In otherwords how do I the same thing as this code:

oPkg.Connections.Item(2).DataSource = strPath

Here is the sp:

CREATE PROCEDURE dbo.spExecuteDTSPKG
@Server varchar(255),
@PkgName varchar(255), -- Package Name (Defaults to most recent version)
@ServerPWD varchar(255) = Null, -- Server Password if using SQL Security to load Package (UID is SUSER_NAME())
@IntSecurity bit = 1, -- 0 = SQL Server Security, 1 = Integrated Security
@PkgPWD varchar(255) = '' -- Package Password
AS
SET NOCOUNT ON

DECLARE @hr int, @ret int, @oPKG int, @Cmd varchar(1000)
Select @ret = 0

-- Create a Pkg Object
EXEC @hr = sp_OACreate 'DTS.Package', @oPKG OUTPUT

SET @Cmd = 'LoadFromSQLServer("' + @Server +'", "", "", 256, "' + @PkgPWD + '", , , "' + @PkgName + '")'

EXEC @hr = sp_OAMethod @oPKG, @Cmd, NULL

-- Execute Pkg
EXEC @hr = sp_OAMethod @oPKG, 'Execute'

-- Unitialize the Pkg
EXEC @hr = sp_OAMethod @oPKG, 'UnInitialize'

-- Clean Up
EXEC @hr = sp_OADestroy @oPKG

RETURN @ret
GO

--
William R

Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Executing a DTS Form Store Proc & Changing the connection - 06-13-2004 , 12:23 AM






You will have to use sp_OASetProperty on the Connection object and the
property you want to set is the DataSource Property

--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"WhiskRomeo" <wrlucasD0N0TSPAM (AT) Xemaps (DOT) com> wrote

Quote:
The below SP (thanks to Database Journal (but simplified)) executes my
DTS.

However, I need to modify one of the connections (XLS file path) before
execution.
Thus, I would need to add another parameter @Path for example.

But how do I change the connection information within the Stored
Procedure. In otherwords how do I the same thing as this code:

oPkg.Connections.Item(2).DataSource = strPath

Here is the sp:

CREATE PROCEDURE dbo.spExecuteDTSPKG
@Server varchar(255),
@PkgName varchar(255), -- Package Name (Defaults to most recent version)
@ServerPWD varchar(255) = Null, -- Server Password if using SQL Security
to load Package (UID is SUSER_NAME())
@IntSecurity bit = 1, -- 0 = SQL Server Security, 1 = Integrated Security
@PkgPWD varchar(255) = '' -- Package Password
AS
SET NOCOUNT ON

DECLARE @hr int, @ret int, @oPKG int, @Cmd varchar(1000)
Select @ret = 0

-- Create a Pkg Object
EXEC @hr = sp_OACreate 'DTS.Package', @oPKG OUTPUT

SET @Cmd = 'LoadFromSQLServer("' + @Server +'", "", "", 256, "' + @PkgPWD
+ '", , , "' + @PkgName + '")'

EXEC @hr = sp_OAMethod @oPKG, @Cmd, NULL

-- Execute Pkg
EXEC @hr = sp_OAMethod @oPKG, 'Execute'

-- Unitialize the Pkg
EXEC @hr = sp_OAMethod @oPKG, 'UnInitialize'

-- Clean Up
EXEC @hr = sp_OADestroy @oPKG

RETURN @ret
GO

--
William R



Reply With Quote
  #3  
Old   
WhiskRomeo
 
Posts: n/a

Default Re: Executing a DTS Form Store Proc & Changing the connection - 06-13-2004 , 11:39 AM



I have added a parameter to the sp for the path and the following statement following sp_OACreate.

EXEC @hr = sp_OASetProperty @oPKG, "Connections.Item(2).DataSource", @XLSPath

The new sp executes just fine but it pulls from the hardcoded datasource instead of the new path.

The path is a string like "D:\PPS\GradFoto\GF1-062404.xls" where d is a drive on the server.


--
William R


"Allan Mitchell" wrote:

Quote:
You will have to use sp_OASetProperty on the Connection object and the
property you want to set is the DataSource Property

--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"WhiskRomeo" <wrlucasD0N0TSPAM (AT) Xemaps (DOT) com> wrote in message
news:8C896A13-6DE3-4F47-8BA9-3CEF0A74D6E4 (AT) microsoft (DOT) com...
The below SP (thanks to Database Journal (but simplified)) executes my
DTS.

However, I need to modify one of the connections (XLS file path) before
execution.
Thus, I would need to add another parameter @Path for example.

But how do I change the connection information within the Stored
Procedure. In otherwords how do I the same thing as this code:

oPkg.Connections.Item(2).DataSource = strPath

Here is the sp:

CREATE PROCEDURE dbo.spExecuteDTSPKG
@Server varchar(255),
@PkgName varchar(255), -- Package Name (Defaults to most recent version)
@ServerPWD varchar(255) = Null, -- Server Password if using SQL Security
to load Package (UID is SUSER_NAME())
@IntSecurity bit = 1, -- 0 = SQL Server Security, 1 = Integrated Security
@PkgPWD varchar(255) = '' -- Package Password
AS
SET NOCOUNT ON

DECLARE @hr int, @ret int, @oPKG int, @Cmd varchar(1000)
Select @ret = 0

-- Create a Pkg Object
EXEC @hr = sp_OACreate 'DTS.Package', @oPKG OUTPUT

SET @Cmd = 'LoadFromSQLServer("' + @Server +'", "", "", 256, "' + @PkgPWD
+ '", , , "' + @PkgName + '")'

EXEC @hr = sp_OAMethod @oPKG, @Cmd, NULL

-- Execute Pkg
EXEC @hr = sp_OAMethod @oPKG, 'Execute'

-- Unitialize the Pkg
EXEC @hr = sp_OAMethod @oPKG, 'UnInitialize'

-- Clean Up
EXEC @hr = sp_OADestroy @oPKG

RETURN @ret
GO

--
William R




Reply With Quote
  #4  
Old   
WhiskRomeo
 
Posts: n/a

Default Re: Executing a DTS Form Store Proc & Changing the connection - 06-13-2004 , 12:27 PM



Actually, the connection object should be in sinqle quotes.
The error I get back is the index of 2 (base 1) is out of range. But this is the connection I want.

When I specify by name instead of index, the error is:

Connection 'PPSInputBatch' was not found

--
William R


"Allan Mitchell" wrote:

Quote:
You will have to use sp_OASetProperty on the Connection object and the
property you want to set is the DataSource Property

--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"WhiskRomeo" <wrlucasD0N0TSPAM (AT) Xemaps (DOT) com> wrote in message
news:8C896A13-6DE3-4F47-8BA9-3CEF0A74D6E4 (AT) microsoft (DOT) com...
The below SP (thanks to Database Journal (but simplified)) executes my
DTS.

However, I need to modify one of the connections (XLS file path) before
execution.
Thus, I would need to add another parameter @Path for example.

But how do I change the connection information within the Stored
Procedure. In otherwords how do I the same thing as this code:

oPkg.Connections.Item(2).DataSource = strPath

Here is the sp:

CREATE PROCEDURE dbo.spExecuteDTSPKG
@Server varchar(255),
@PkgName varchar(255), -- Package Name (Defaults to most recent version)
@ServerPWD varchar(255) = Null, -- Server Password if using SQL Security
to load Package (UID is SUSER_NAME())
@IntSecurity bit = 1, -- 0 = SQL Server Security, 1 = Integrated Security
@PkgPWD varchar(255) = '' -- Package Password
AS
SET NOCOUNT ON

DECLARE @hr int, @ret int, @oPKG int, @Cmd varchar(1000)
Select @ret = 0

-- Create a Pkg Object
EXEC @hr = sp_OACreate 'DTS.Package', @oPKG OUTPUT

SET @Cmd = 'LoadFromSQLServer("' + @Server +'", "", "", 256, "' + @PkgPWD
+ '", , , "' + @PkgName + '")'

EXEC @hr = sp_OAMethod @oPKG, @Cmd, NULL

-- Execute Pkg
EXEC @hr = sp_OAMethod @oPKG, 'Execute'

-- Unitialize the Pkg
EXEC @hr = sp_OAMethod @oPKG, 'UnInitialize'

-- Clean Up
EXEC @hr = sp_OADestroy @oPKG

RETURN @ret
GO

--
William R




Reply With Quote
  #5  
Old   
WhiskRomeo
 
Posts: n/a

Default Re: Executing a DTS Form Store Proc & Changing the connection - 06-13-2004 , 01:50 PM



Found the problem.

I have to load the package before I can access the conneciton property (duh)! I was trying the set the connection right after the create.

The below sp works

CREATE PROCEDURE dbo.spExecuteDTSPKG
@Server varchar(255),
@PkgName varchar(255), -- Package Name (Defaults to most recent version)
@XLSPath varchar(255), -- Path to Source File
@ServerPWD varchar(255) = Null, -- Server Password if using SQL Security to load Package (UID is SUSER_NAME())
@IntSecurity bit = 1, -- 0 = SQL Server Security, 1 = Integrated Security
@PkgPWD varchar(255) = '' -- Package Password
AS
SET NOCOUNT ON

DECLARE @hr int, @ret int, @oPKG int, @Cmd varchar(1000)
Select @ret = 0

-- Create a Pkg Object
EXEC @hr = sp_OACreate 'DTS.Package', @oPKG OUTPUT


SET @Cmd = 'LoadFromSQLServer("' + @Server +'", "", "", 256, "' + @PkgPWD + '", , , "' + @PkgName + '")'

EXEC @hr = sp_OAMethod @oPKG, @Cmd, NULL

EXEC @hr = sp_OASetProperty @oPKG, 'Connections.Item("PPSBatchInput").DataSource', @XLSPath
If @hr <> 0
BEGIN
PRINT '*** OASetProperty for Connection Failed***'
EXEC sp_OAGetErrorInfo @oPkg
RETURN
END

-- Execute Pkg
EXEC @hr = sp_OAMethod @oPKG, 'Execute'

-- Unitialize the Pkg
EXEC @hr = sp_OAMethod @oPKG, 'UnInitialize'

-- Clean Up
EXEC @hr = sp_OADestroy @oPKG

RETURN @ret
GO


--
William R




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.