Showing posts with label executing. Show all posts
Showing posts with label executing. Show all posts

Monday, March 19, 2012

Controls disappear

Is it not possible to execute one package and then design another package? I am executing one package and trying to design another package and just have a grey window in the control tool box that says:

"there are no usable controls in this group. Drag an item onto this text to add it to the toolbar"

Can I only get my controls by dragging when another package is executing? Where do I drag them from?

Thanks,

Kayda

You seem quite new to this and some things are very odd about SSIS.

The controls are dragged from the Toolbox window. Get this by clicking on the "spanner and hammer" icon at the top. Or Crtl+Alt+X or via the menu View->Toolbox.

You have to be on the Control Flow or Data Flow panels. You get different tools for the 2 different contexts.

Also, you need to check you are executing the correct package. In the Solution Explorer, under the SSIS Packages folder right click on your xxxxxx.dtsx file and select "Set as StartUp Object" for the package you want to execute ... or just select "Execute Package" to run the one you want. You have to stop debugging the previous package before you design or run the next one.

Since you have already done one package, I may have misunderstood your questions.

Hope this helps

|||

Hi Kayda,

The Visual Studio Integrated Development Environment (IDE) changes modes when the debugger starts. It disables most editing functionality until it exits debug mode. It also hides controls in the toolboxes. This is by design.

Although the package execution is complete, the IDE remains in debug mode until stopped (Shift-F5 or the VCR-style Stop button will do it).

This is different from DTS and a normal source of confusion for folks making the transition.

Hope this helps,
Andy

|||Perhaps you could open a second session of BIDS; or use DTExec or DTExecUI to execute the packages while still developing other packages

Controlling outbound IP address on a SQL Cluster

Hello,

Is there any way to specify which IP address is used when executing a SQL Job. We recently found that Jobs starting from our cluster (Windows 2003 SQL 2000 SP 4 in a Active / Passive configuration) use the IP address from the local node rather then the virtual IP address tied to the SQL cluster. Jobs executing from the remote SQL server are running. The use of the local address has caused a failure at the firewall.

Thanks

mjdenn

Moving to the right alias so SQL Agent experts can reply to your question.

Thanks,

Zhiqiang Feng

Thursday, March 8, 2012

control flow of execution of statement

is there a way to check to see if the previous sql statement has completely executed before executing the next statement?

I have a stored procedure that basically has several insert statements. At the end of the insert statements I call bcp to write the table to a text file. The first insert will write a header record into the table. Then it will insert a bunch of records that are selected from other tables and then lastly will write the footer record. My dilemna is that for some reason the first insert of the header record isn't actually happening until the middle of the second set of inserts where it inserts several records from another table. so basically my file ends up looking like this

payment record
payment record
payment record
Header Record
payment record
payment record
payment record
payment record
Footer Record

Can I tell it to wait for the first insert to complete before starting the other insert?

Can you post your sp, table structure and a actual sample of the data? SP's by their nature do not execute the next statement until the previous one has completed. I wonder if you have an index on your table that is causing the data to sort in the format that you have shown even though the insert is happening in the correct order...|||

Here is the stored procedure

The table I am inserting stuff into literally is one field. It is just a way to grab and format data from another table and then call bcp to write the data to a text file.

ALTER PROCEDURE [dbo].[PREPAREFILE]
@.DATE_PAID as char(8), @.HEADER as varchar(MAX), @.FOOTER as varchar(MAX)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.

SET NOCOUNT ON;
END

BEGIN
DELETE FROM Temp_Formatted
END

BEGIN
INSERT INTO Temp_Formatted
(formattedRecord)
VALUES (@.HEADER)
END

BEGIN
INSERT INTO Temp_Formatted
(formattedRecord)

SELECT '6' + '000000000000001' + bill_number + installment + space(224) as stub
FROM dbo.Temp_Unformatted

END

BEGIN
INSERT INTO Temp_Formatted
(formattedRecord)

SELECT '7' + '000000000000001' + @.DATE_PAID + space(1) + replace(right('000000000' + rtrim(cast(amount as decimal(9,2))), 12),'.','') + space(224) as payment
FROM dbo.Temp_Unformatted

END

BEGIN
INSERT INTO Temp_Formatted
(formattedRecord)
VALUES (@.FOOTER)
END

Then I call bcp to write the Temp_formatted data to a text file.

What happens though in both the table and the file I get this:
Stub
Stub
Stub
Header
Stub
Stub
Payment
Payment
Payment
Payment
Payment
Footer

What I need is:
Header
stub
stub
stub
stub
stub
payment
payment
payment
payment
Footer

Of course my example output is scaled down. I have over 40,000 stub and payment records.

|||

Does your table have an index on the formattedRecord column?

Looks the first byte for a stub is always "6", first byte for a payment is "7". What is does the Header record look like, especially the first byte (you are passing as an arguement), what does the Footer record look like, especially the first byte (you are passing as an arguement)?

If a table does not have an index, it will store the data in the format that it receives it. The insert statements in your proc run sequentially (meaning each insert has to complete successfully before the next insert statement executes).

|||well, for testing purposes i've been just passing 'header' for @.header and 'footer' for @.footer. But it will always be different. No, there are no indexes on the the formatted table. No keys no indexes...nothing. I even ran a test with only writing header/payments/footer without stubs and it does basically the same thing. I will get a bunch of payments then the header and then the rest of the payments and then the footer. It is really really weird.|||

I'm at a loss. Do you know what the header and footer rows will look like (really what the first byte will be)? Will it always be the same?

You could get around this by using a query with an order by clause to load your bcp.

As an example, let's say your header will always start with 'h' and your footer will always start with 'f'

Select formattedRecord
From Temp_Formatted
Order by
Case left(formattedRecord, 1)
When 'h' then 1
When '6' then 6
When '7' then 7
When 'f' then 9
Else 8 -- This forces everything else to sort before the footer
End

Try the above query and see if that gives you the order you want.

|||yeah they are going to be different. Gee, you would think this would be pretty simple. I don't get why it is doing it this way. its really odd that it inserts between the stubs. You don't know of anyway to do the check to see if the header is there first?|||If you know what the header will look like (and it is formatted differently than the footer), you can probably modify the order by clause I posted. Only other thing I can suggest is to drop the table and recreate it. I've never seen this happen before.|||

SQL is a set-based language and tables are unordered set of rows. So even if you insert some rows in a particular order you will not be able to read it in the same order without specifying an ORDER BY clause in your SELECT statement. Any other assumption to the order of the rows based on index or query plan is incorrect. The easiest way to solve this problem is to add an identity column to the table and then modify your BCP to use queryout option & issue a SELECT on the table with the ORDER BY clause specifying the identity column. This will ensure that the you can retrieve rows in the order in which you inserted and this assumes that there is only one instance of SP inserting data into the table at any point in time.

Alternatively, you can do this without any table at all like below:

-- PrepareFile SP

SELECT t.Data

FROM (

SELECT 0, @.HEADER

UNION ALL
SELECT 1, '6' + '000000000000001' + bill_number + installment + space(224) as stub
FROM dbo.Temp_Unformatted

UNION ALL

SELECT 1, '7' + '000000000000001' + @.DATE_PAID + space(1) + replace(right('000000000' + rtrim(cast(amount as decimal(9,2))), 12),'.','') + space(224) as payment
FROM dbo.Temp_Unformatted

UNION ALL

SELECT 2, @.FOOTER

) as t(SortCol, Data)
ORDER BY t.SortCol

Now, change your BCP to just call this SP using queryout option.

Sunday, February 19, 2012

Consuming events in code

Hi,

Ive been taking a look at how to consume events from a package when executing programatically.

Ive got some code (copied below) that creates a package programatically, adds a sequence container then within that adds a script task , then executes it using the overloaded method of Package.Execute() that takes an IDtsEvents argument.

My class that implements IDtsEvents simply output a message to the console for each event type.

Weird thing is, when I execute, this is the only output I get:

Starting...
OnPreValidate: Microsoft.SqlServer.Dts.Runtime.Package
OnPreValidate: Microsoft.SqlServer.Dts.Runtime.Sequence
OnPreValidate: Microsoft.SqlServer.Dts.Runtime.TaskHost
OnPostValidate:Microsoft.SqlServer.Dts.Runtime.TaskHost
OnQueryCancel
Package ran successfully

What I find weird is that I dont get information for loads of other event types. I would at least have expected to see some OnPostExecute events.

Anyone know why i dont see all of the events?

Thanks

Jamie

Heres the code:

Code Snippet

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SqlServer.Dts.Runtime;

using Microsoft.SqlServer.Dts.Tasks.ScriptTask;

namespace Package_API

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Starting...");

Package p = new Package();

p.InteractiveMode = true;

p.OfflineMode = true;

// Add a Script Task to the package.

Sequence s = (Sequence)p.Executables.Add("STOCK:Sequence");

TaskHost taskH = (TaskHost)s.Executables.Add("STOCK:ScriptTask");

// Run the package.

DtsEvents events = new DtsEvents();

p.Execute(null,null,events,null,null);

//p.Execute();

if (p.ExecutionResult == DTSExecResult.Failure || p.ExecutionStatus == DTSExecStatus.Abend)

Console.WriteLine("Package failed or abended");

else

Console.WriteLine("Package ran successfully");

Console.ReadLine();

}

}

}

// Class that implements the IDTSEvents interface:

public sealed class DtsEvents : IDTSEvents

{

void IDTSEvents.OnPreExecute(Executable exec, ref bool fireAgain)

{

Console.WriteLine("OnPreExecute: " + exec.ToString());

}

void IDTSEvents.OnBreakpointHit(IDTSBreakpointSite breakpointSite, BreakpointTarget breakpointTarget)

{

Console.WriteLine("OnBreakpointHit");

}

void IDTSEvents.OnCustomEvent(TaskHost taskHost,string eventName,string eventText,ref Object[] arguments,string subComponent,ref bool fireAgain)

{

Console.WriteLine("CustomEvent");

}

void IDTSEvents.OnPreValidate(Executable exec, ref bool fireAgain)

{

Console.WriteLine("OnPreValidate: " + exec.ToString());

}

void IDTSEvents.OnPostValidate(Executable exec, ref bool fireAgain)

{

Console.WriteLine("OnPostValidate:" + exec.ToString());

}

void IDTSEvents.OnWarning(DtsObject source,int warningCode,string subComponent,string description,string helpFile,int helpContext,string idofInterfaceWithError)

{

Console.WriteLine("OnWarning");

}

void IDTSEvents.OnInformation(DtsObject source,int informationCode,string subComponent,string description,string helpFile,int helpContext,string idofInterfaceWithError,ref bool fireAgain)

{

Console.WriteLine("OnInformation");

}

void IDTSEvents.OnPostExecute(Executable exec, ref bool fireAgain)

{

Console.WriteLine("OnPostExecute");

}

bool IDTSEvents.OnError(DtsObject source,int errorCode,string subComponent,string description,string helpFile,int helpContext,string idofInterfaceWithError)

{

Console.WriteLine("OnError");

return true;

}

void IDTSEvents.OnTaskFailed(TaskHost taskHost)

{

Console.WriteLine("OnTaskFailed");

}

void IDTSEvents.OnProgress(TaskHost taskHost,string progressDescription,int percentComplete,int progressCountLow,int progressCountHigh,string subComponent,ref bool fireAgain)

{

Console.WriteLine("OnProgress");

}

bool IDTSEvents.OnQueryCancel()

{

Console.WriteLine("OnQueryCancel");

return true;

}

void IDTSEvents.OnExecutionStatusChanged(Executable exec,DTSExecStatus newStatus,ref bool fireAgain)

{

Console.WriteLine("OnExecutionStatusChanged");

}

void IDTSEvents.OnVariableValueChanged(DtsContainer DtsContainer,Variable variable,ref bool fireAgain)

{

Console.WriteLine("OnVariableValueChanged");

}

}

By returning true from OnQueryCancel, you are cancelling the package Smile

Just add Console.WriteLine(p.ExecutionResult) - it should be Cancelled.

Return false from this method, or inherit from DefaultEvents and only override methods that you actually need.

|||

Michael Entin - MSFT wrote:

By returning true from OnQueryCancel, you are cancelling the package

Just add Console.WriteLine(p.ExecutionResult) - it should be Cancelled.

Return false from this method, or inherit from DefaultEvents and only override methods that you actually need.

DOH!!!

What a dumbass. I should have realised that!


Thanks Michael!

-Jamie

|||

How odd, Jamie. According my class I can follow each event -including post and pre executing...

Dim EventsSSIS As EventosSSIS
EventsSSIS = New EventosSSIS()
sResultDts = pkg.Execute(Nothing, Nothing, EventsSSIS, Nothing, Nothing)

Public Class EventosSSIS
Implements IDTSEvents
Public proceso As Int16 = 0

Sub OnPostValidate(ByVal exec As Executable, ByRef fireAgain As Boolean) Implements IDTSEvents.OnPostValidate
End Sub
Sub OnProgress(ByVal taskHost As TaskHost, ByVal progressDescription As String, ByVal percentComplete As Integer, ByVal progressCountLow As Integer, ByVal progressCountHigh As Integer, ByVal subComponent As String, ByRef fireAgain As Boolean) Implements IDTSEvents.OnProgress
End Sub
Sub OnPreExecute(ByVal exec As Executable, ByRef fireAgain As Boolean) Implements IDTSEvents.OnPreExecute
End Sub
Sub OnPreValidate(ByVal exec As Executable, ByRef fireAgain As Boolean) Implements IDTSEvents.OnPreValidate
End Sub
Sub OnPostExecute(ByVal exec As Executable, ByRef fireAgain As Boolean) Implements IDTSEvents.OnPostExecute
End Sub
Sub OnWarning(ByVal source As DtsObject, ByVal warningCode As Integer, ByVal subComponent As String, ByVal description As String, ByVal helpFile As String, ByVal helpContext As Integer, ByVal idofInterfaceWithError As String) Implements IDTSEvents.OnWarning
End Sub
Sub OnInformation(ByVal [source] As DtsObject, ByVal informationCode As Integer, ByVal subComponent As String, ByVal description As String, ByVal helpFile As String, ByVal helpContext As Integer, ByVal idofInterfaceWithError As String, ByRef fireAgain As Boolean) Implements IDTSEvents.OnInformation
End Sub
Sub OnTaskFailed(ByVal taskHost As TaskHost) Implements IDTSEvents.OnTaskFailed
End Sub
Function OnError(ByVal source As DtsObject, ByVal errorCode As Integer, ByVal subComponent As String, ByVal description As String, ByVal helpFile As String, ByVal helpContext As Integer, ByVal idofInterfaceWithError As String) As Boolean Implements IDTSEvents.OnError
End Function
Sub OnExecutionStatusChanged(ByVal exec As Executable, ByVal newStatus As DTSExecStatus, ByRef fireAgain As Boolean) Implements IDTSEvents.OnExecutionStatusChanged
End Sub
Sub OnCustomEvent(ByVal taskHost As TaskHost, ByVal eventName As String, ByVal eventText As String, ByRef arguments() As Object, ByVal subComponent As String, ByRef fireAgain As Boolean) Implements IDTSEvents.OnCustomEvent
End Sub
Sub OnBreakpointHit(ByVal breakpointSite As IDTSBreakpointSite, ByVal breakpointTarget As BreakpointTarget) Implements IDTSEvents.OnBreakpointHit
End Sub
Sub OnVariableValueChanged(ByVal dtsContainer As DtsContainer, ByVal variable As Variable, ByRef fireAgain As Boolean) Implements IDTSEvents.OnVariableValueChanged
End Sub
Public Overloads Function OnQueryCancel() As Boolean Implements IDTSEvents.OnQueryCancel
Dim cancelar As Int32 = 0
OnQueryCancel = False
Try
Using cn As New SqlConnection(sCadenadeConexion)
cn.Open()
Using cm As SqlCommand = cn.CreateCommand
cm.CommandType = Data.CommandType.Text
cm.CommandText = "SELECT cancelar FROM sis_controlthread where idproceso= " & proceso
cancelar = cm.ExecuteScalar
If cancelar Then
OnQueryCancel = True
Else
OnQueryCancel = False
End If
cm.Dispose()
End Using
cn.Close()
End Using
Catch ex As Exception
TratamientoErrores(0, 0, 11, ex.Message, "On Query Cancel")
End Try
End Function
End Class