Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Friday, March 30, 2012

Help with SQL Mapping

First time trying to import a pretty simple XML file into a SQL
table. I've been reading annotated XSD file docs for the past 3 hours
and it's just not clear to me. Here's my XML
<?xml version="1.0" standalone="yes"?>
<InvoiceBalanceData>
<InvoiceBalanceData>
<documentnumber>12345</documentnumber>
<invoicebalance>99.99</invoicebalance>
<invoicenumber>INV123</invoicenumber>
<invoicetrantype>FS</invoicetrantype>
</InvoiceBalanceData>
<InvoiceBalanceData>
<documentnumber>444</documentnumber>
<invoicebalance>88.88</invoicebalance>
<invoicenumber>INV345</invoicenumber>
<invoicetrantype>AB</invoicetrantype>
</InvoiceBalanceData>
</InvoiceBalanceData>
Can someone help me with my annotated XSD file? tia.
On Dec 13, 10:31 am, Larry Bud <larrybud2...@.yahoo.com> wrote:
> First time trying to import a pretty simple XML file into a SQL
> table. I've been reading annotated XSD file docs for the past 3 hours
> and it's just not clear to me. Here's my XML
> <?xml version="1.0" standalone="yes"?>
> <InvoiceBalanceData>
> <InvoiceBalanceData>
> <documentnumber>12345</documentnumber>
> <invoicebalance>99.99</invoicebalance>
> <invoicenumber>INV123</invoicenumber>
> <invoicetrantype>FS</invoicetrantype>
> </InvoiceBalanceData>
> <InvoiceBalanceData>
> <documentnumber>444</documentnumber>
> <invoicebalance>88.88</invoicebalance>
> <invoicenumber>INV345</invoicenumber>
> <invoicetrantype>AB</invoicetrantype>
> </InvoiceBalanceData>
> </InvoiceBalanceData>
> Can someone help me with my annotated XSD file? tia.
I should add that after I attempt to import the XML, the script
finishes successfully (this is from a DTS package), but no rows are
imported into the table.
|||I would process it as attribute centric
declare @.xml xml
SET @.xml =
'<root>
<InvoiceBalanceData documentnumber="12345" invoicebalance="99.99"
invoicenumber="INV123" invoicetrantype="FS" />
<InvoiceBalanceData documentnumber="444" invoicebalance="88.88"
invoicenumber="INV345" invoicetrantype="AB" />
</root>'
select @.xml
SELECT
[inv].[ref].value('@.documentnumber', 'int'),
[inv].[ref].value('@.invoicebalance', 'money')
FROM @.xml.nodes('/root/InvoiceBalanceData') [inv]([ref])
See SQL Server BOL as well.
-- Create tables for later population using OPENXML.
CREATE TABLE Customers (CustomerID varchar(20) primary key,
ContactName varchar(20),
CompanyName varchar(20))
GO
CREATE TABLE Orders( CustomerID varchar(20), OrderDate datetime)
GO
DECLARE @.docHandle int
DECLARE @.xmlDocument nvarchar(max) -- or xml type
SET @.xmlDocument = N'<ROOT>
<Customers CustomerID="XYZAA" ContactName="Joe" CompanyName="Company1">
<Orders CustomerID="XYZAA" OrderDate="2000-08-25T00:00:00"/>
<Orders CustomerID="XYZAA" OrderDate="2000-10-03T00:00:00"/>
</Customers>
<Customers CustomerID="XYZBB" ContactName="Steve"
CompanyName="Company2">No Orders yet!
</Customers>
</ROOT>'
EXEC sp_xml_preparedocument @.docHandle OUTPUT, @.xmlDocument
-- Use OPENXML to provide rowset consisting of customer data.
INSERT Customers
SELECT *
FROM OPENXML(@.docHandle, N'/ROOT/Customers')
WITH Customers
-- Use OPENXML to provide rowset consisting of order data.
INSERT Orders
SELECT *
FROM OPENXML(@.docHandle, N'//Orders')
WITH Orders
-- Using OPENXML in a SELECT statement.
SELECT * FROM OPENXML(@.docHandle, N'/ROOT/Customers/Orders') WITH
(CustomerID nchar(5) '../@.CustomerID', OrderDate datetime)
-- Remove the internal representation of the XML document.
EXEC sp_xml_removedocument @.docHandle
"Larry Bud" <larrybud2002@.yahoo.com> wrote in message
news:6ebab460-5eda-4c48-a4be-1ef478130ea3@.i29g2000prf.googlegroups.com...
> On Dec 13, 10:31 am, Larry Bud <larrybud2...@.yahoo.com> wrote:
> I should add that after I attempt to import the XML, the script
> finishes successfully (this is from a DTS package), but no rows are
> imported into the table.

Help with SQL Mapping

First time trying to import a pretty simple XML file into a SQL
table. I've been reading annotated XSD file docs for the past 3 hours
and it's just not clear to me. Here's my XML
<?xml version="1.0" standalone="yes"?>
<InvoiceBalanceData>
<InvoiceBalanceData>
<documentnumber>12345</documentnumber>
<invoicebalance>99.99</invoicebalance>
<invoicenumber>INV123</invoicenumber>
<invoicetrantype>FS</invoicetrantype>
</InvoiceBalanceData>
<InvoiceBalanceData>
<documentnumber>444</documentnumber>
<invoicebalance>88.88</invoicebalance>
<invoicenumber>INV345</invoicenumber>
<invoicetrantype>AB</invoicetrantype>
</InvoiceBalanceData>
</InvoiceBalanceData>
Can someone help me with my annotated XSD file? tia.On Dec 13, 10:31 am, Larry Bud <larrybud2...@.yahoo.com> wrote:
> First time trying to import a pretty simple XML file into a SQL
> table. I've been reading annotated XSD file docs for the past 3 hours
> and it's just not clear to me. Here's my XML
> <?xml version="1.0" standalone="yes"?>
> <InvoiceBalanceData>
> <InvoiceBalanceData>
> <documentnumber>12345</documentnumber>
> <invoicebalance>99.99</invoicebalance>
> <invoicenumber>INV123</invoicenumber>
> <invoicetrantype>FS</invoicetrantype>
> </InvoiceBalanceData>
> <InvoiceBalanceData>
> <documentnumber>444</documentnumber>
> <invoicebalance>88.88</invoicebalance>
> <invoicenumber>INV345</invoicenumber>
> <invoicetrantype>AB</invoicetrantype>
> </InvoiceBalanceData>
> </InvoiceBalanceData>
> Can someone help me with my annotated XSD file? tia.
I should add that after I attempt to import the XML, the script
finishes successfully (this is from a DTS package), but no rows are
imported into the table.|||I would process it as attribute centric
declare @.xml xml
SET @.xml =
'<root>
<InvoiceBalanceData documentnumber="12345" invoicebalance="99.99"
invoicenumber="INV123" invoicetrantype="FS" />
<InvoiceBalanceData documentnumber="444" invoicebalance="88.88"
invoicenumber="INV345" invoicetrantype="AB" />
</root>'
select @.xml
SELECT
[inv].[ref].value('@.documentnumber', 'int'),
[inv].[ref].value('@.invoicebalance', 'money')
FROM @.xml.nodes('/root/InvoiceBalanceData') [inv]([ref])
See SQL Server BOL as well.
-- Create tables for later population using OPENXML.
CREATE TABLE Customers (CustomerID varchar(20) primary key,
ContactName varchar(20),
CompanyName varchar(20))
GO
CREATE TABLE Orders( CustomerID varchar(20), OrderDate datetime)
GO
DECLARE @.docHandle int
DECLARE @.xmlDocument nvarchar(max) -- or xml type
SET @.xmlDocument = N'<ROOT>
<Customers CustomerID="XYZAA" ContactName="Joe" CompanyName="Company1">
<Orders CustomerID="XYZAA" OrderDate="2000-08-25T00:00:00"/>
<Orders CustomerID="XYZAA" OrderDate="2000-10-03T00:00:00"/>
</Customers>
<Customers CustomerID="XYZBB" ContactName="Steve"
CompanyName="Company2">No Orders yet!
</Customers>
</ROOT>'
EXEC sp_xml_preparedocument @.docHandle OUTPUT, @.xmlDocument
-- Use OPENXML to provide rowset consisting of customer data.
INSERT Customers
SELECT *
FROM OPENXML(@.docHandle, N'/ROOT/Customers')
WITH Customers
-- Use OPENXML to provide rowset consisting of order data.
INSERT Orders
SELECT *
FROM OPENXML(@.docHandle, N'//Orders')
WITH Orders
-- Using OPENXML in a SELECT statement.
SELECT * FROM OPENXML(@.docHandle, N'/ROOT/Customers/Orders') WITH
(CustomerID nchar(5) '../@.CustomerID', OrderDate datetime)
-- Remove the internal representation of the XML document.
EXEC sp_xml_removedocument @.docHandle
"Larry Bud" <larrybud2002@.yahoo.com> wrote in message
news:6ebab460-5eda-4c48-a4be-1ef478130ea3@.i29g2000prf.googlegroups.com...
> On Dec 13, 10:31 am, Larry Bud <larrybud2...@.yahoo.com> wrote:
> I should add that after I attempt to import the XML, the script
> finishes successfully (this is from a DTS package), but no rows are
> imported into the table.

Wednesday, March 28, 2012

Help with SQL 2005 solutions

nomad
If I understood you correctly
1) Open Solution within you have added .sql files (1-for SP,2-for Views)
2) When you click on the file it opens a object explorer windows
3) Add your object to opened window (relevant for object type) and save it.
So , the next time you open the file your script should be saved there
"nomad" <d.bedgood@.ntlworld.com> wrote in message
news:1172065721.265467.175850@.a75g2000cwd.googlegr oups.com...
> Hi,
> I want to be able to use source control from within SQL 2005. I know
> how to add a new solution with a project attached. And I know how to
> add existing .sql scripts to it. My quesiton is, how can I split them
> up so that I can add all stored procedure scripts into a folder called
> Stored Procedures, all views into a folder called Views etc instead of
> them all going into the Query folder.
> Appreciate any help on this.
>
Ahh, I see what you mean. I'm affraid you cannot do that
"nomad" <d.bedgood@.ntlworld.com> wrote in message
news:1172068385.736309.197940@.k78g2000cwa.googlegr oups.com...
> On 21 Feb, 14:16, "Uri Dimant" <u...@.iscar.co.il> wrote:
> I know how to do all of this. My question is, in the solution you
> have folders called Connections, Queries & Miscellaneous. I want to
> be able to add folders called Stored Procedures, Views etc so that I
> can add my SP .sql scripts into Stored Procedure folder, Views scripts
> into Views folder etc so that it is easier to differentiate between
> your scripts.
>

Friday, March 23, 2012

Help with Sending file to server using ftp task

Doe anyone know how to do this. I keep getting an error remote path missing "/" but it doesn't contain a "/".

Mike

If you could give more detail, that would help.|||

I'm trying to connect to a FTP server running on z/OS and has MvS operating system. The remoter parameters In the FTP task editor in ssis calls for a "/" at the beginning of the remote path but the remote path I am uploading to starts out with a single quote and not a forward slash. Is there a way around this?

thanks,

Mike

|||Did you try putting a "/" in front?|||

I figured it out using a ftp script.

|||That's what I have had to resort to at times also. Some of the FTP task functionality just doesn't seem to function like it should.

Wednesday, March 21, 2012

Help with returning a well formed XML for 1 row using XDS

Hi,
I am trying to use SQLXML and have created the template file and schema
files. Everything works fine except that the XML returned is not well
formed i.e. it has the root tag but all the elements are all in one
row. I have tried the root=root option and it is not helping. I have
gone thru all newsgroups / googled it and I am running the latest
version of SQLXML 3.0 SP2 on a SQL2000 Server. It is running on Win XP
w/ SP2. Any help on how to resolve the problem would be appreciated!Can you give a short example of the data you are getting and the one you
would like to get?
Thanks
Michael
<snandaca@.gmail.com> wrote in message
news:1125614930.833716.88890@.g14g2000cwa.googlegroups.com...
> Hi,
> I am trying to use SQLXML and have created the template file and schema
> files. Everything works fine except that the XML returned is not well
> formed i.e. it has the root tag but all the elements are all in one
> row. I have tried the root=root option and it is not helping. I have
> gone thru all newsgroups / googled it and I am running the latest
> version of SQLXML 3.0 SP2 on a SQL2000 Server. It is running on Win XP
> w/ SP2. Any help on how to resolve the problem would be appreciated!
>

Help with returning a well formed XML for 1 row using XDS

Hi,
I am trying to use SQLXML and have created the template file and schema
files. Everything works fine except that the XML returned is not well
formed i.e. it has the root tag but all the elements are all in one
row. I have tried the root=root option and it is not helping. I have
gone thru all newsgroups / googled it and I am running the latest
version of SQLXML 3.0 SP2 on a SQL2000 Server. It is running on Win XP
w/ SP2. Any help on how to resolve the problem would be appreciated!
Can you give a short example of the data you are getting and the one you
would like to get?
Thanks
Michael
<snandaca@.gmail.com> wrote in message
news:1125614930.833716.88890@.g14g2000cwa.googlegro ups.com...
> Hi,
> I am trying to use SQLXML and have created the template file and schema
> files. Everything works fine except that the XML returned is not well
> formed i.e. it has the root tag but all the elements are all in one
> row. I have tried the root=root option and it is not helping. I have
> gone thru all newsgroups / googled it and I am running the latest
> version of SQLXML 3.0 SP2 on a SQL2000 Server. It is running on Win XP
> w/ SP2. Any help on how to resolve the problem would be appreciated!
>

Help with read from a text column

All, I have a table containing an ID and a text column. I need to dump the
content of the table into a text file using the following code:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
GO
BEGIN TRAN
set textsize 62713
DECLARE @.ptr varbinary(16)
SELECT @.ptr = textptr(note)
FROM notes
WHERE id = 307
READTEXT note @.ptr 0 62713
COMMIT TRAN
GO
However, I get only 8K out of the text column where I am suppose to get
62713. I ran OSQL to re-direct the output to a file.
thanks.
JohnHi
Query Analyser has a maximum column width or 8192 characters and you can not
increase the size beyone that in the options dialog. Although I have not
found anything to say that osql has a similar limit I can get 8342 character
s
out.
To write to a file correctly look at
http://support.microsoft.com/defaul...kb;en-us;317043
John
"John Smith" wrote:

> All, I have a table containing an ID and a text column. I need to dump the
> content of the table into a text file using the following code:
> SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
> GO
> BEGIN TRAN
> set textsize 62713
> DECLARE @.ptr varbinary(16)
> SELECT @.ptr = textptr(note)
> FROM notes
> WHERE id = 307
> READTEXT note @.ptr 0 62713
> COMMIT TRAN
> GO
> However, I get only 8K out of the text column where I am suppose to get
> 62713. I ran OSQL to re-direct the output to a file.
> thanks.
> John

Monday, February 27, 2012

Help with moving DB from 2000 to 2005 folders

Hi.
After installing SQLExpress on my DB Server, I have
the following file directory:
80
90
MSSQL
MSSQL.1
I am noticing that the DB that I am working with is in
MSSQL > DATA > MY_DB.MDF
On the Web Server, I want to connect to (server name)/SQLEXPRESS so I
am guessing I need to move MY_DB.MDF from folder MSSQL > DATA to
folder MSSQL.1 > MSSQL > DATA.
How do I do this? Is this as simple as moving the MDF and LDF files
from the 2000 folder to the 2005 folder? Or, is it more involved?
Also, should I be keeping the 80 and MSQL folders
on my hard drive?
Thanks in advance!
When you connect to SQLExpress from your Web Server, you ask the rdbms to
give you some resultset. Why should you move your databases? I suppose you
migrate them or at least detach them from old instance and attach them to
SQLExpress.
The folders hierarchy you see is just the default location for SQL files
(You can find there, for example, the system databases SQL installed during
setup). You can locate your Databases everywhere you like.
Gilberto Zampatti
"pbd22" wrote:

> Hi.
> After installing SQLExpress on my DB Server, I have
> the following file directory:
> 80
> 90
> MSSQL
> MSSQL.1
> I am noticing that the DB that I am working with is in
> MSSQL > DATA > MY_DB.MDF
> On the Web Server, I want to connect to (server name)/SQLEXPRESS so I
> am guessing I need to move MY_DB.MDF from folder MSSQL > DATA to
> folder MSSQL.1 > MSSQL > DATA.
> How do I do this? Is this as simple as moving the MDF and LDF files
> from the 2000 folder to the 2005 folder? Or, is it more involved?
> Also, should I be keeping the 80 and MSQL folders
> on my hard drive?
> Thanks in advance!
>

Help with moving DB from 2000 to 2005 folders

Hi.
After installing SQLExpress on my DB Server, I have
the following file directory:
80
90
MSSQL
MSSQL.1
I am noticing that the DB that I am working with is in
MSSQL > DATA > MY_DB.MDF
On the Web Server, I want to connect to (server name)/SQLEXPRESS so I
am guessing I need to move MY_DB.MDF from folder MSSQL > DATA to
folder MSSQL.1 > MSSQL > DATA.
How do I do this? Is this as simple as moving the MDF and LDF files
from the 2000 folder to the 2005 folder? Or, is it more involved?
Also, should I be keeping the 80 and MSQL folders
on my hard drive?
Thanks in advance!When you connect to SQLExpress from your Web Server, you ask the rdbms to
give you some resultset. Why should you move your databases? I suppose you
migrate them or at least detach them from old instance and attach them to
SQLExpress.
The folders hierarchy you see is just the default location for SQL files
(You can find there, for example, the system databases SQL installed during
setup). You can locate your Databases everywhere you like.
Gilberto Zampatti
"pbd22" wrote:
> Hi.
> After installing SQLExpress on my DB Server, I have
> the following file directory:
> 80
> 90
> MSSQL
> MSSQL.1
> I am noticing that the DB that I am working with is in
> MSSQL > DATA > MY_DB.MDF
> On the Web Server, I want to connect to (server name)/SQLEXPRESS so I
> am guessing I need to move MY_DB.MDF from folder MSSQL > DATA to
> folder MSSQL.1 > MSSQL > DATA.
> How do I do this? Is this as simple as moving the MDF and LDF files
> from the 2000 folder to the 2005 folder? Or, is it more involved?
> Also, should I be keeping the 80 and MSQL folders
> on my hard drive?
> Thanks in advance!
>|||Ok, thanks. I am learning as I go.
I have a follow-up question. Its related, but different so
I will repost. Thanks for your help!
Gilberto Zampatti wote:
> When you connect to SQLExpress from your Web Server, you ask the rdbms to
> give you some resultset. Why should you move your databases? I suppose you
> migrate them or at least detach them from old instance and attach them to
> SQLExpress.
> The folders hierarchy you see is just the default location for SQL files
> (You can find there, for example, the system databases SQL installed during
> setup). You can locate your Databases everywhere you like.
> Gilberto Zampatti
> "pbd22" wrote:
> > Hi.
> >
> > After installing SQLExpress on my DB Server, I have
> > the following file directory:
> >
> > 80
> > 90
> > MSSQL
> > MSSQL.1
> >
> > I am noticing that the DB that I am working with is in
> >
> > MSSQL > DATA > MY_DB.MDF
> >
> > On the Web Server, I want to connect to (server name)/SQLEXPRESS so I
> > am guessing I need to move MY_DB.MDF from folder MSSQL > DATA to
> > folder MSSQL.1 > MSSQL > DATA.
> >
> > How do I do this? Is this as simple as moving the MDF and LDF files
> > from the 2000 folder to the 2005 folder? Or, is it more involved?
> > Also, should I be keeping the 80 and MSQL folders
> > on my hard drive?
> >
> > Thanks in advance!
> >
> >

Help with moving DB from 2000 to 2005 folders

Hi.
After installing SQLExpress on my DB Server, I have
the following file directory:
80
90
MSSQL
MSSQL.1
I am noticing that the DB that I am working with is in
MSSQL > DATA > MY_DB.MDF
On the Web Server, I want to connect to (server name)/SQLEXPRESS so I
am guessing I need to move MY_DB.MDF from folder MSSQL > DATA to
folder MSSQL.1 > MSSQL > DATA.
How do I do this? Is this as simple as moving the MDF and LDF files
from the 2000 folder to the 2005 folder? Or, is it more involved?
Also, should I be keeping the 80 and MSQL folders
on my hard drive?
Thanks in advance!When you connect to SQLExpress from your Web Server, you ask the rdbms to
give you some resultset. Why should you move your databases? I suppose you
migrate them or at least detach them from old instance and attach them to
SQLExpress.
The folders hierarchy you see is just the default location for SQL files
(You can find there, for example, the system databases SQL installed during
setup). You can locate your Databases everywhere you like.
Gilberto Zampatti
"pbd22" wrote:

> Hi.
> After installing SQLExpress on my DB Server, I have
> the following file directory:
> 80
> 90
> MSSQL
> MSSQL.1
> I am noticing that the DB that I am working with is in
> MSSQL > DATA > MY_DB.MDF
> On the Web Server, I want to connect to (server name)/SQLEXPRESS so I
> am guessing I need to move MY_DB.MDF from folder MSSQL > DATA to
> folder MSSQL.1 > MSSQL > DATA.
> How do I do this? Is this as simple as moving the MDF and LDF files
> from the 2000 folder to the 2005 folder? Or, is it more involved?
> Also, should I be keeping the 80 and MSQL folders
> on my hard drive?
> Thanks in advance!
>|||Ok, thanks. I am learning as I go.
I have a follow-up question. Its related, but different so
I will repost. Thanks for your help!
Gilberto Zampatti wote:[vbcol=seagreen]
> When you connect to SQLExpress from your Web Server, you ask the rdbms to
> give you some resultset. Why should you move your databases? I suppose you
> migrate them or at least detach them from old instance and attach them to
> SQLExpress.
> The folders hierarchy you see is just the default location for SQL files
> (You can find there, for example, the system databases SQL installed durin
g
> setup). You can locate your Databases everywhere you like.
> Gilberto Zampatti
> "pbd22" wrote:
>

Help with modifying a data source''s query at runtime

Please help figure out what is wrong with my code. The script is supposed to load a package (from file). The loaded package already has everything set up to run a query against a local server and output the results to an Excel file. The reason for the outer script is because I need to change the query based on a global variable. When the query changes, though, I think the existing dataflow Path is no longer valid, so I should remove it and re-create another one with the new input mappings. Here is my code, which runs and throws an exception at the AcquireConnections call.

The error is

Error: 0x2 at Script Task: The script threw an exception: Exception from HRESULT: 0xC020801B

I pieced together this code from the examples in the online books, but I am not sure what to do.

' Microsoft SQL Server Integration Services Script Task

' Write scripts using Microsoft Visual Basic

' The ScriptMain class is the entry point of the Script Task.

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Runtime

Imports Microsoft.SqlServer.Dts.Pipeline

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Public Class ScriptMain

Public Sub Main()

'

Dim app As Microsoft.SqlServer.Dts.Runtime.Application = New Application()

Dim package As Microsoft.SqlServer.Dts.Runtime.Package = _

app.LoadPackage("c:\systime\ExcelOut\ExcelOut\ExcelOutDo.dtsx", Nothing)

Dim pkgVars As Variables = package.Variables

Dim gsVar As Variable = pkgVars("User::gsExcelFile")

Dim currVars As Variables = Dts.Variables

Console.WriteLine(Dts.Variables("User::gsExcelFile").Value)

gsVar.Value = Dts.Variables("User::gsExcelFile").Value

pkgVars("User::gsQuery").Value = Dts.Variables("User::gsQuery").Value

pkgVars("User::gsCreateTable").Value = Dts.Variables("User::gsCreateTable").Value

Dim e As Executable = package.Executables("ExcelOutTask")

Dim thMainPipe As Microsoft.SqlServer.Dts.Runtime.TaskHost = _

CType(e, Microsoft.SqlServer.Dts.Runtime.TaskHost)

Dim dataFlowTask As MainPipe = CType(thMainPipe.InnerObject, MainPipe)

' Get the source component.

Dim SourceComponent As IDTSComponentMetaData90 = _

dataFlowTask.ComponentMetaDataCollection("Local Source")

Dim srcDesignTime As CManagedComponentWrapper = SourceComponent.Instantiate()

srcDesignTime.ProvideComponentProperties()

' Reinitialize the metadata.

srcDesignTime.AcquireConnections(vbNull)

srcDesignTime.ReinitializeMetaData()

srcDesignTime.ReleaseConnections()

' Get the destination component.

Dim destination As IDTSComponentMetaData90 = _

dataFlowTask.ComponentMetaDataCollection("Excel Destination")

Dim destDesignTime As CManagedComponentWrapper = destination.Instantiate()

destDesignTime.ProvideComponentProperties()

' Create the path.

dataFlowTask.PathCollection.RemoveAll()

Dim path As IDTSPath90 = dataFlowTask.PathCollection.New()

path.AttachPathAndPropagateNotifications(SourceComponent.OutputCollection(0), _

destination.InputCollection(0))

'Console.WriteLine(dataFlowTask.PathCollection.Count)

Dim ret As DTSExecResult

ret = package.Execute()

Console.WriteLine(ret.ToString)

Dts.TaskResult = Dts.Results.Success

End Sub

End Class

I think (but I'm not positive) that you need to call ReinitializeMetaData on the destination component after updating the path, so it has a chance to correct any changed columns. Actually, if you call that, you might not have to remove and add the path at all.

|||

Before running the AcquireConnections you need to re-link the connection with the source component. It has the connection ID persisted and you need to get the connection object (use the ID to find it) and assign it to the component's runtime connection.

HTH,

Bob

Help with modifying a data source''s query at runtime

Please help figure out what is wrong with my code. The script is supposed to load a package (from file). The loaded package already has everything set up to run a query against a local server and output the results to an Excel file. The reason for the outer script is because I need to change the query based on a global variable. When the query changes, though, I think the existing dataflow Path is no longer valid, so I should remove it and re-create another one with the new input mappings. Here is my code, which runs and throws an exception at the AcquireConnections call.

The error is

Error: 0x2 at Script Task: The script threw an exception: Exception from HRESULT: 0xC020801B

I pieced together this code from the examples in the online books, but I am not sure what to do.

' Microsoft SQL Server Integration Services Script Task

' Write scripts using Microsoft Visual Basic

' The ScriptMain class is the entry point of the Script Task.

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Runtime

Imports Microsoft.SqlServer.Dts.Pipeline

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Public Class ScriptMain

Public Sub Main()

'

Dim app As Microsoft.SqlServer.Dts.Runtime.Application = New Application()

Dim package As Microsoft.SqlServer.Dts.Runtime.Package = _

app.LoadPackage("c:\systime\ExcelOut\ExcelOut\ExcelOutDo.dtsx", Nothing)

Dim pkgVars As Variables = package.Variables

Dim gsVar As Variable = pkgVars("User::gsExcelFile")

Dim currVars As Variables = Dts.Variables

Console.WriteLine(Dts.Variables("User::gsExcelFile").Value)

gsVar.Value = Dts.Variables("User::gsExcelFile").Value

pkgVars("User::gsQuery").Value = Dts.Variables("User::gsQuery").Value

pkgVars("User::gsCreateTable").Value = Dts.Variables("User::gsCreateTable").Value

Dim e As Executable = package.Executables("ExcelOutTask")

Dim thMainPipe As Microsoft.SqlServer.Dts.Runtime.TaskHost = _

CType(e, Microsoft.SqlServer.Dts.Runtime.TaskHost)

Dim dataFlowTask As MainPipe = CType(thMainPipe.InnerObject, MainPipe)

' Get the source component.

Dim SourceComponent As IDTSComponentMetaData90 = _

dataFlowTask.ComponentMetaDataCollection("Local Source")

Dim srcDesignTime As CManagedComponentWrapper = SourceComponent.Instantiate()

srcDesignTime.ProvideComponentProperties()

' Reinitialize the metadata.

srcDesignTime.AcquireConnections(vbNull)

srcDesignTime.ReinitializeMetaData()

srcDesignTime.ReleaseConnections()

' Get the destination component.

Dim destination As IDTSComponentMetaData90 = _

dataFlowTask.ComponentMetaDataCollection("Excel Destination")

Dim destDesignTime As CManagedComponentWrapper = destination.Instantiate()

destDesignTime.ProvideComponentProperties()

' Create the path.

dataFlowTask.PathCollection.RemoveAll()

Dim path As IDTSPath90 = dataFlowTask.PathCollection.New()

path.AttachPathAndPropagateNotifications(SourceComponent.OutputCollection(0), _

destination.InputCollection(0))

'Console.WriteLine(dataFlowTask.PathCollection.Count)

Dim ret As DTSExecResult

ret = package.Execute()

Console.WriteLine(ret.ToString)

Dts.TaskResult = Dts.Results.Success

End Sub

End Class

I think (but I'm not positive) that you need to call ReinitializeMetaData on the destination component after updating the path, so it has a chance to correct any changed columns. Actually, if you call that, you might not have to remove and add the path at all.

|||

Before running the AcquireConnections you need to re-link the connection with the source component. It has the connection ID persisted and you need to get the connection object (use the ID to find it) and assign it to the component's runtime connection.

HTH,

Bob

Help with modifying a data source''s query at runtime

Please help figure out what is wrong with my code. The script is supposed to load a package (from file). The loaded package already has everything set up to run a query against a local server and output the results to an Excel file. The reason for the outer script is because I need to change the query based on a global variable. When the query changes, though, I think the existing dataflow Path is no longer valid, so I should remove it and re-create another one with the new input mappings. Here is my code, which runs and throws an exception at the AcquireConnections call.

The error is

Error: 0x2 at Script Task: The script threw an exception: Exception from HRESULT: 0xC020801B

I pieced together this code from the examples in the online books, but I am not sure what to do.

' Microsoft SQL Server Integration Services Script Task

' Write scripts using Microsoft Visual Basic

' The ScriptMain class is the entry point of the Script Task.

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Runtime

Imports Microsoft.SqlServer.Dts.Pipeline

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Public Class ScriptMain

Public Sub Main()

'

Dim app As Microsoft.SqlServer.Dts.Runtime.Application = New Application()

Dim package As Microsoft.SqlServer.Dts.Runtime.Package = _

app.LoadPackage("c:\systime\ExcelOut\ExcelOut\ExcelOutDo.dtsx", Nothing)

Dim pkgVars As Variables = package.Variables

Dim gsVar As Variable = pkgVars("User::gsExcelFile")

Dim currVars As Variables = Dts.Variables

Console.WriteLine(Dts.Variables("User::gsExcelFile").Value)

gsVar.Value = Dts.Variables("User::gsExcelFile").Value

pkgVars("User::gsQuery").Value = Dts.Variables("User::gsQuery").Value

pkgVars("User::gsCreateTable").Value = Dts.Variables("User::gsCreateTable").Value

Dim e As Executable = package.Executables("ExcelOutTask")

Dim thMainPipe As Microsoft.SqlServer.Dts.Runtime.TaskHost = _

CType(e, Microsoft.SqlServer.Dts.Runtime.TaskHost)

Dim dataFlowTask As MainPipe = CType(thMainPipe.InnerObject, MainPipe)

' Get the source component.

Dim SourceComponent As IDTSComponentMetaData90 = _

dataFlowTask.ComponentMetaDataCollection("Local Source")

Dim srcDesignTime As CManagedComponentWrapper = SourceComponent.Instantiate()

srcDesignTime.ProvideComponentProperties()

' Reinitialize the metadata.

srcDesignTime.AcquireConnections(vbNull)

srcDesignTime.ReinitializeMetaData()

srcDesignTime.ReleaseConnections()

' Get the destination component.

Dim destination As IDTSComponentMetaData90 = _

dataFlowTask.ComponentMetaDataCollection("Excel Destination")

Dim destDesignTime As CManagedComponentWrapper = destination.Instantiate()

destDesignTime.ProvideComponentProperties()

' Create the path.

dataFlowTask.PathCollection.RemoveAll()

Dim path As IDTSPath90 = dataFlowTask.PathCollection.New()

path.AttachPathAndPropagateNotifications(SourceComponent.OutputCollection(0), _

destination.InputCollection(0))

'Console.WriteLine(dataFlowTask.PathCollection.Count)

Dim ret As DTSExecResult

ret = package.Execute()

Console.WriteLine(ret.ToString)

Dts.TaskResult = Dts.Results.Success

End Sub

End Class

I think (but I'm not positive) that you need to call ReinitializeMetaData on the destination component after updating the path, so it has a chance to correct any changed columns. Actually, if you call that, you might not have to remove and add the path at all.

|||

Before running the AcquireConnections you need to re-link the connection with the source component. It has the connection ID persisted and you need to get the connection object (use the ID to find it) and assign it to the component's runtime connection.

HTH,

Bob