Showing posts with label output. Show all posts
Showing posts with label output. Show all posts

Tuesday, March 27, 2012

can I get the Parent task in a custom data flow task?

I'm building a custom data flow task to handle errors in a generic way in C#. I want to output the Task name (the name of the Data flow) as well as the Task name that is inputting data into my custom task.

Is there a way to get both the task name and the previous data flow task name that's inputting the data?

THanks in advance,
-Chris

PS, the VariableContainer didn't seem to contain any of the system variables- ex. the below statement returned false.

this.VariableDispenser.Contains("System::SourceName")

Are you talking about a control flow task or a data flow component? For a dataflow component you can not get any information about any other component other than yourself.

As for the variable dispenser, unless you have added variables to it via the lock methods then it contains no variables. Additionally, there is no such system variable as SourceName.

Thanks,
Matt|||I am talking about a dataflow component.

Do I have to add the system variables to the VariableDispenser?

Thanks for your help Matt,
-Chris|||Yes, you have to add all variables to the variable dispenser in the form of the lock methods. Otherwise the variable dispenser is empty.

Matt|||

I added the System::SourceName variable to the custom data flow component by using LockOneForWrite, but gave an error that that variable doesn't exist.

Is there a place where I can find a listing of the system variables available at the data flow component level?

|||As I mentioned in my original post, there is no such system variable. You can look in the designer to see all the system variable that are available.

Matt|||

Matt David wrote:

As I mentioned in my original post, there is no such system variable. You can look in the designer to see all the system variable that are available.

Matt

Just to clarify Matt's point...SSIS actually does have a System::SourceName variable but it is only available in the eventhandler container. You can't reference it in your control-flow.

-Jamie|||I believe you can get hold of the component next to it in the flow, by looking at one of the input collections. However you can't find out the component that added a column to a flow.

can I get the Parent task in a custom data flow task?

I'm building a custom data flow task to handle errors in a generic way in C#. I want to output the Task name (the name of the Data flow) as well as the Task name that is inputting data into my custom task.

Is there a way to get both the task name and the previous data flow task name that's inputting the data?

THanks in advance,
-Chris

PS, the VariableContainer didn't seem to contain any of the system variables- ex. the below statement returned false.

this.VariableDispenser.Contains("System::SourceName")

Are you talking about a control flow task or a data flow component? For a dataflow component you can not get any information about any other component other than yourself.

As for the variable dispenser, unless you have added variables to it via the lock methods then it contains no variables. Additionally, there is no such system variable as SourceName.

Thanks,
Matt|||I am talking about a dataflow component.

Do I have to add the system variables to the VariableDispenser?

Thanks for your help Matt,
-Chris|||Yes, you have to add all variables to the variable dispenser in the form of the lock methods. Otherwise the variable dispenser is empty.

Matt|||

I added the System::SourceName variable to the custom data flow component by using LockOneForWrite, but gave an error that that variable doesn't exist.

Is there a place where I can find a listing of the system variables available at the data flow component level?

|||As I mentioned in my original post, there is no such system variable. You can look in the designer to see all the system variable that are available.

Matt|||

Matt David wrote:

As I mentioned in my original post, there is no such system variable. You can look in the designer to see all the system variable that are available.

Matt

Just to clarify Matt's point...SSIS actually does have a System::SourceName variable but it is only available in the eventhandler container. You can't reference it in your control-flow.

-Jamie|||I believe you can get hold of the component next to it in the flow, by looking at one of the input collections. However you can't find out the component that added a column to a flow.

can i get the output of 'sp_columns' system SP into a table through T-SQL

Hi,
I want to collect the output of system stored procedure 'sp_columns' into a temporary table. Please suggest how can i achieve this.

Ashu Sharma

Create a temp table with columns as described at sp_columns in BOL and then do
INSERT INTO your_temp_table EXEC sp_columns
--
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de|||Thanks Franksql

Wednesday, March 7, 2012

Can columns be added to an error output?

When setting an output's "IsErrorOut" property to true, is it also possible to add additional columns to that error output?

I'd like to add a message beyond the standard errorCode and errorColumn columns, a column which is the "specific error message", not just a lookup on the errorCode.

IDTSOutput90 outError = ComponentMetaData.OutputCollection.New();
outError.Name = "Error Output";
outError.IsErrorOut = true;

// Add extra column here, e.g. ErrorMessage

Answering my own question. The answer is 'YES', you can enhance the error output.

You can add the columns as follows in ProvideComponentProperties. The part I was missing was since the error output was synchronous, the column index needed to be looked in in the input buffer, not the output buffer. Native SQL ADO destination adapter error codes are much more convenient then the next to useless error codes produced by the OLEDB destination adapter.

===============================================================================

// In ProvideComponentProperties()
// Add error message to error output column collection
// do so after the call to .IsErrorOut, to ensure that ErrorCode and ErrorColumn
// are added first for consistency
IDTSOutputColumnCollection90 outputColumnCollection =
outError.OutputColumnCollection;
IDTSOutputColumn90 outputColumn = outputColumnCollection.New();
outputColumn.Name = ERR_MESSAGE_COLUMN_NAME;
outputColumn.SetDataTypeProperties(DataType.DT_WSTR, 250, 0, 0, 0);

===============================================================================

// In PreExecute()
// Get the input and the external column collection
IDTSInput90 input = ComponentMetaData.InputCollection[0];
IDTSExternalMetadataColumnCollection90 externalcols =
input.ExternalMetadataColumnCollection;

// Deterine index of error Message column
IDTSOutput90 output = ComponentMetaData.OutputCollection["Error Output"];
IDTSOutputColumnCollection90 outputColumnCollection =
output.OutputColumnCollection;
errMessageColumnIndex = BufferManager.FindColumnByLineageID(
input.Buffer, outputColumnCollection[ERR_MESSAGE_COLUMN_NAME].LineageID);

===============================================================================

// In ProcessInput(int inputID, PipelineBuffer buffer)
if (m_rowdisp == DTSRowDisposition.RD_RedirectRow)
{
#region set native error code and message
SqlException sqlEx = (e as SqlException);
if (sqlEx != null) {
// Retrieve the native SqlException error code
errorCode = sqlEx.Number;
}
if (String.IsNullOrEmpty(sqlEx.Message))
buffer.SetNull(errMessageColumnIndex);
else
errorMessage = sqlEx.Message;
// Retrieve and load the native SqlException message
buffer[errMessageColumnIndex] = (errorMessage.Length <= 250 ?
errorMessage : errorMessage.Substring(0, 250));
#endregion

buffer.DirectErrorRow(errorOutputID, errorCode, iCol);
}

===============================================================================

|||

Can you give me more details on this. I will wait to see if you reply beofre I elaborate..

It sounds like this is something I am looking to do based on my post:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1509511&SiteID=1

|||

Rob,

The code above works for a custom component. If you want to implement your functionality as a custom component then it will work. In the other thread that you linked to you said you were attempting this i a script component - and that is a slightly different kettle of fish.

-Jamie

|||

Wow, you are everywhere Jamie. Yes, now that I see what he was doing, you are correct. Not sure where to go now, but we will continue to develop this process. and I will check back here and some other places.

Say, when you submit these SSIS enhancment requests, (Connect) how long does it take - or what does it take to see these implemented?

|||

ronemac wrote:

Say, when you submit these SSIS enhancment requests, (Connect) how long does it take - or what does it take to see these implemented?

If they were to do it (and that's a huge if) then the earliest you could expect it is in the next release of SQL Server. That is due to be Summer 2008.

-Jamie

Can columns be added to an error output?

When setting an output's "IsErrorOut" property to true, is it also possible to add additional columns to that error output?

I'd like to add a message beyond the standard errorCode and errorColumn columns, a column which is the "specific error message", not just a lookup on the errorCode.

IDTSOutput90 outError = ComponentMetaData.OutputCollection.New();
outError.Name = "Error Output";
outError.IsErrorOut = true;

// Add extra column here, e.g. ErrorMessage

Answering my own question. The answer is 'YES', you can enhance the error output.

You can add the columns as follows in ProvideComponentProperties. The part I was missing was since the error output was synchronous, the column index needed to be looked in in the input buffer, not the output buffer. Native SQL ADO destination adapter error codes are much more convenient then the next to useless error codes produced by the OLEDB destination adapter.

===============================================================================

// In ProvideComponentProperties()
// Add error message to error output column collection
// do so after the call to .IsErrorOut, to ensure that ErrorCode and ErrorColumn
// are added first for consistency
IDTSOutputColumnCollection90 outputColumnCollection =
outError.OutputColumnCollection;
IDTSOutputColumn90 outputColumn = outputColumnCollection.New();
outputColumn.Name = ERR_MESSAGE_COLUMN_NAME;
outputColumn.SetDataTypeProperties(DataType.DT_WSTR, 250, 0, 0, 0);

===============================================================================

// In PreExecute()
// Get the input and the external column collection
IDTSInput90 input = ComponentMetaData.InputCollection[0];
IDTSExternalMetadataColumnCollection90 externalcols =
input.ExternalMetadataColumnCollection;

// Deterine index of error Message column
IDTSOutput90 output = ComponentMetaData.OutputCollection["Error Output"];
IDTSOutputColumnCollection90 outputColumnCollection =
output.OutputColumnCollection;
errMessageColumnIndex = BufferManager.FindColumnByLineageID(
input.Buffer, outputColumnCollection[ERR_MESSAGE_COLUMN_NAME].LineageID);

===============================================================================

// In ProcessInput(int inputID, PipelineBuffer buffer)
if (m_rowdisp == DTSRowDisposition.RD_RedirectRow)
{
#region set native error code and message
SqlException sqlEx = (e as SqlException);
if (sqlEx != null) {
// Retrieve the native SqlException error code
errorCode = sqlEx.Number;
}
if (String.IsNullOrEmpty(sqlEx.Message))
buffer.SetNull(errMessageColumnIndex);
else
errorMessage = sqlEx.Message;
// Retrieve and load the native SqlException message
buffer[errMessageColumnIndex] = (errorMessage.Length <= 250 ?
errorMessage : errorMessage.Substring(0, 250));
#endregion

buffer.DirectErrorRow(errorOutputID, errorCode, iCol);
}

===============================================================================

|||

Can you give me more details on this. I will wait to see if you reply beofre I elaborate..

It sounds like this is something I am looking to do based on my post:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1509511&SiteID=1

|||

Rob,

The code above works for a custom component. If you want to implement your functionality as a custom component then it will work. In the other thread that you linked to you said you were attempting this i a script component - and that is a slightly different kettle of fish.

-Jamie

|||

Wow, you are everywhere Jamie. Yes, now that I see what he was doing, you are correct. Not sure where to go now, but we will continue to develop this process. and I will check back here and some other places.

Say, when you submit these SSIS enhancment requests, (Connect) how long does it take - or what does it take to see these implemented?

|||

ronemac wrote:

Say, when you submit these SSIS enhancment requests, (Connect) how long does it take - or what does it take to see these implemented?

If they were to do it (and that's a huge if) then the earliest you could expect it is in the next release of SQL Server. That is due to be Summer 2008.

-Jamie

Friday, February 24, 2012

Can an SQL Server stored procedure write output to an excel formated file?

Hi,
To clarify the previous post.
I would like to write a stored procedure that a client can call. The
stored procedure will then output its result in an excel file.
Thanks,
chariaYou have things a little reversed. You should have the stored procedure
return the data. How you call the report will determine how it is rendered
(HTML, CSV, PDF, Excel etc). When integrating reports you can use URL
integration or webservices. Neither of which would be that easy from a
stored procedure.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
<cpeters5@.gmail.com> wrote in message
news:1120582350.023702.281780@.g43g2000cwa.googlegroups.com...
> Hi,
> To clarify the previous post.
> I would like to write a stored procedure that a client can call. The
> stored procedure will then output its result in an excel file.
> Thanks,
> charia
>

Can a value be assigned to an Output parameter and be used in a where clause?

I need to update a table using a stored procedure that "UPSERTS". In this case, @.OfficeId is passed with ParameterDirection.Output

So when I update I assign the value to OfficeId like this (the office id value is being correctly assigned):

SqlParameter OfficeIdParam = new SqlParameter("@.OfficeId", SqlDbType.Int, 4);
if (_officeId > 0) { OfficeIdParam.Value = _officeId; }
OfficeIdParam.Direction = ParameterDirection.Output;

The following segment of the stored procedure is throwing an error that the OfficeId does not exist:

Update -- @.OfficeId int output

if not exists (select 1 from ORG_Office where OfficeId=@.OfficeId)
begin
RAISERROR ('OfficeId does not exist in ORG_Office: E002', 16, 1) -- OfficeId does not exist.
return -1
end

May this approach work, and if the operation turns out to be an Insert I may do this:

select @.error_code = @.@.ERROR, @.OfficeId= scope_identity()

Thank you,

jspurlin

I am thinking you need to add the parameter conditionally, instead of adding it and then setting the direction conditionally. (you might need to fix syntax errors as I dont do .NET code and definetely not in C#Smile )

If (_officeId > 0) {

SqlParameter OfficeIdParam = new SqlParameter("@.OfficeId", SqlDbType.Int, 4);
OfficeIdParam.Direction = ParameterDirection.Output;

}

else {

SqlParameter OfficeIdParam = new SqlParameter("@.OfficeId", SqlDbType.Int, 4);

}

Friday, February 10, 2012

calling vbscript from SP

I am trying to call a VB script file with the following command,

xp_cmdshell 'cscript c:\file.vbs'

But its giving the following output -

Microsoft (R) Windows Script Host Version 5.1 for Windows
Copyright (C) Microsoft Corporation 1996-1999. All rights reserved.
NULL
Input Error: Can not find script file "c:\file.vbs".
NULL
----
If i changed the command to

xp_cmdshell 'cscript c:file.vbs'

it gives the folowing error -

Input Error: Can not find script file "C:\WINNT\system32\file.vbs".

Actually my main intention is to call a url from the sql server where '
i can pass some value. Plz let me know if its the right step and whts
going wrong.

Thanks & regards,

-dkoushikHow about using XML - http://www.awprofessional.com/articles/article.asp?p=102307&seqNum=9 and another possibility is to directly access the ODBC lowlevel APIs directly. I've no exp.using languages like Visual Basic. You may have some luck accessing the stored procedures
using SQL Namespace APIs & MSEQ.|||Hi satya,
Thanks for your reply. But I guess u have misunderstood my question.

My Actual intention is to call web url from the SqlServe DB.
I have done the same in oracle. I have used Java stored procedure
where I have called a web url and the java sp is get called from a
Oracle function. I am sure there is nothing called java stored proc in Sql server.

So How can I achive the same result in Sql Server.

I was just trying some thing using xp_cmdshell (a system SP)
which can call any VB script which in turn will call the web url.

Plz help if you have any idea regarding this.

Thanks & Regards,

-- dkoushik


Originally posted by Satya
How about using XML - http://www.awprofessional.com/articles/article.asp?p=102307&seqNum=9 and another possibility is to directly access the ODBC lowlevel APIs directly. I've no exp.using languages like Visual Basic. You may have some luck accessing the stored procedures
using SQL Namespace APIs & MSEQ.|||If you are using xp_cmdshell, you've got 90% of the battle won. xp_cmdshell can launch any file that the NT Login used by MS-SQL can see, using whatever tools are available on the machine that is running SQL Server.

If you can log into the machine that runs your SQL Server, using the same login credentials that SQL Server uses, then you will have almost exactly the same conditions to test with that the xp_cmdshell will run under. Find a command string you can type to get something to happend, and you can then issue the exact same command using xp_cmdshell.

-PatP|||Hi Pat,

Thanks for the reply.
What I understood from your response is ,

I have to execute the xp_cmdshell in the database server
query analyzer. I have done the same thing but nothing is happening.

But this time its not giving any error. But the result its showing as NULL.

Do have any idea whats happening.

please help.