Showing posts with label console. Show all posts
Showing posts with label console. Show all posts

Monday, March 19, 2012

ExecuteNonQuery hangs in Timer event notification

If I call ExecuteNonQuery() in a timer event callback in a console application, it hangs. Why is that?

.B ekiM

class Program
{
static SqlConnection conn = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=NONEOFYOURBISUINESS;Data Source=localhost");

static void Main(string[] args)
{
NativeMethods.MEMORYSTATUSEX mem = new NativeMethods.MEMORYSTATUSEX();
NativeMethods.GlobalMemoryStatusEx(mem);
Console.WriteLine("{0} bytes", mem.ullAvailPhys);

System.Timers.Timer aTimer = new System.Timers.Timer();
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 1000;
aTimer.Enabled = true;

// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

Console.ReadLine();
}

private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
NativeMethods.MEMORYSTATUSEX mem = new NativeMethods.MEMORYSTATUSEX();
NativeMethods.GlobalMemoryStatusEx(mem);

SqlCommand cmd = new SqlCommand(
"INSERT INTO Observation (StatisticType, StatisticObserved, StatisticValue) VALUES (1, @.When, @.AvailPhys);\n" +
"INSERT INTO Observation (StatisticType, StatisticObserved, StatisticValue) VALUES (2, @.When, @.AvailPageFile);\n" +
"INSERT INTO Observation (StatisticType, StatisticObserved, StatisticValue) VALUES (3, @.When, @.AvailVirtual);\n" +
"INSERT INTO Observation (StatisticType, StatisticObserved, StatisticValue) VALUES (4, @.When, @.AvailExtendedVirtual);\n");

DateTime dt = DateTime.Now;
cmd.Parameters.AddWithValue("AvailPhys", mem.ullAvailPhys);
cmd.Parameters.AddWithValue("AvailPageFile", mem.ullAvailPageFile);
cmd.Parameters.AddWithValue("AvailVirtual", mem.ullAvailVirtual);
cmd.Parameters.AddWithValue("AvailExtendedVirtual", mem.ullAvailExtendedVirtual);
cmd.Parameters.AddWithValue("When", dt);

cmd.ExecuteNonQuery();

Console.WriteLine("Inserted {0}", dt);
}

}

A-hah! It's not hanging; it's just throwing an exception that the runtime itself catches, then doesn't report.|||Is the problem solved then, or you you want to elaborate on the error message ?

Jens K. Suessmeyer.

http://www.sqlserver2005.de
|||
The problem is that the runtime catches an exception. It shouldn't: it hasn't published a contract saying it will catch exceptions. It also offers very little indication that it did catch the exception.

These problems are certainly not solved.

ExecuteNonQuery hangs in Timer event notification

If I call ExecuteNonQuery() in a timer event callback in a console application, it hangs. Why is that?

.B ekiM

class Program
{
static SqlConnection conn = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=NONEOFYOURBISUINESS;Data Source=localhost");

static void Main(string[] args)
{
NativeMethods.MEMORYSTATUSEX mem = new NativeMethods.MEMORYSTATUSEX();
NativeMethods.GlobalMemoryStatusEx(mem);
Console.WriteLine("{0} bytes", mem.ullAvailPhys);

System.Timers.Timer aTimer = new System.Timers.Timer();
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 1000;
aTimer.Enabled = true;

// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

Console.ReadLine();
}

private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
NativeMethods.MEMORYSTATUSEX mem = new NativeMethods.MEMORYSTATUSEX();
NativeMethods.GlobalMemoryStatusEx(mem);

SqlCommand cmd = new SqlCommand(
"INSERT INTO Observation (StatisticType, StatisticObserved, StatisticValue) VALUES (1, @.When, @.AvailPhys);\n" +
"INSERT INTO Observation (StatisticType, StatisticObserved, StatisticValue) VALUES (2, @.When, @.AvailPageFile);\n" +
"INSERT INTO Observation (StatisticType, StatisticObserved, StatisticValue) VALUES (3, @.When, @.AvailVirtual);\n" +
"INSERT INTO Observation (StatisticType, StatisticObserved, StatisticValue) VALUES (4, @.When, @.AvailExtendedVirtual);\n");

DateTime dt = DateTime.Now;
cmd.Parameters.AddWithValue("AvailPhys", mem.ullAvailPhys);
cmd.Parameters.AddWithValue("AvailPageFile", mem.ullAvailPageFile);
cmd.Parameters.AddWithValue("AvailVirtual", mem.ullAvailVirtual);
cmd.Parameters.AddWithValue("AvailExtendedVirtual", mem.ullAvailExtendedVirtual);
cmd.Parameters.AddWithValue("When", dt);

cmd.ExecuteNonQuery();

Console.WriteLine("Inserted {0}", dt);
}

}

A-hah! It's not hanging; it's just throwing an exception that the runtime itself catches, then doesn't report.|||Is the problem solved then, or you you want to elaborate on the error message ?

Jens K. Suessmeyer.

http://www.sqlserver2005.de
|||
The problem is that the runtime catches an exception. It shouldn't: it hasn't published a contract saying it will catch exceptions. It also offers very little indication that it did catch the exception.

These problems are certainly not solved.

Monday, March 12, 2012

Execute SSIS package without SSIS console

Hello,

How can i do to execute SSIS package without SSIS console ?

This can occur when you use a hosted database with your hosted web.

thanksHi,
I'm not quite sure what you mean by the SSIS console.

Packages can be executed using DTExec - a command line execution tool. You can also execute packages from managed code.

Does this help?

-Jamie|||Do you mean that i can execute a dts package from an aspx web page ?|||

Coroebus wrote:

Do you mean that i can execute a dts package from an aspx web page ?

Yes. Search this forum for clues.

You should use the Microsoft.SqlServer.ManagedDTS assembly

A few links:
ms-help://MS.VSCC.v80/MS.VSIPCC.v80/MS.SQLSVR.v9.en/dtsref9mref/html/T_Microsoft_SqlServer_Dts_Runtime_Package_Members.htm
ms-help://MS.VSCC.v80/MS.VSIPCC.v80/MS.SQLSVR.v9.en/dtsref9mref/html/M_Microsoft_SqlServer_Dts_Runtime_Package_Execute.htm
-Jamie|||Also, please see the Books Online topic, "Running an Existing Package using Visual Basic."

-Doug
|||

Is there any performance difference in running it from CLR and dtsui or command

vb code link:

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/dtsref9/html/2f9fc1a8-a001-4c54-8c64-63b443725422.htm

Dim app As New Application
Dim pkg As New Package
Dim pkgLocation As String
Dim pkgResults As DTSExecResult

pkgLocation = "C:\\Program Files\\Microsoft SQL Server\90\Samples\\Integration Services\\Package Samples\\CalculatedColumns Sample\\CalculatedColumns\\CalculatedColumns.dtsx"

pkg = app.LoadPackage(pkgLocation, Nothing, True)

pkgResults = pkg.Execute()

|||There might be some performance difference due to different reporting, but for most packages it is very small. It might be noticeable if you execute very fast tasks in a loop.

Designer UI and DtExecUI has some overhead to show the package progress and logging. Designer also executes package out-of-process to ensure designer stability, so it might be slower than other options.

DtExec speed depends on amount of logging and event reporting you turn on using command line.

Executing programmatically does not have any performance penalty.

In the code above please use
pkg = app.LoadPackage(pkgLocation, Nothing)
i.e. use two-argument version of LoadPackage method.

(If you pass True to three-argument version, you get neutral-threaded package COM object, which might be somewhat slower for execution. It is better and faster for package manipulation though).
|||

Is there an alternative LoadPackage method for when the Package is contained within the MSDB database vs. the File System?

Thanks

|||

Steve in Crystal Lake Illinios wrote:

Is there an alternative LoadPackage method for when the Package is contained within the MSDB database vs. the File System?

Thanks

Of course, see Application object documentation in Books Online. There are LoadFromSqlServer and LoadFromDtsServer methods.

|||

Is it possible to set this dtsx file to be scheduled from 6 am to 6 pm from monday to friday ?

Thanks a lot

|||

This is a snippet of code of our vb service:

"Fic" is when you have your dtsx allocated on Windows folder

"Sql" is allocated on MSDB

"dts" is allocated on SSIS Package Store (both Sql Server and Windows folder)

Select Case ObjSSIS.sSourceType

Case "Fic"
pkg = app.LoadPackage(ObjSSIS.sRutaDts & ObjSSIS.sSSISName & ".dtsx", Nothing, True)


Case "Sql"
pkg = app.LoadFromSqlServer(ObjSSIS.sRutaDts & ObjSSIS.sSSISName, ObjSSIS.sServer, Nothing, Nothing, Nothing)
Case "dts"
pkg = app.LoadFromDtsServer(ObjSSIS.sRutaDts & ObjSSIS.sSSISName, ObjSSIS.sServer, Nothing)
Case Else
Throw New ArgumentException("El paquete SSIS no tiene ubicación")
End Select

Execute SSIS package without SSIS console

Hello,

How can i do to execute SSIS package without SSIS console ?

This can occur when you use a hosted database with your hosted web.

thanksHi,
I'm not quite sure what you mean by the SSIS console.

Packages can be executed using DTExec - a command line execution tool. You can also execute packages from managed code.

Does this help?

-Jamie|||Do you mean that i can execute a dts package from an aspx web page ?

|||

Coroebus wrote:

Do you mean that i can execute a dts package from an aspx web page ?

Yes. Search this forum for clues.

You should use the Microsoft.SqlServer.ManagedDTS assembly

A few links:
ms-help://MS.VSCC.v80/MS.VSIPCC.v80/MS.SQLSVR.v9.en/dtsref9mref/html/T_Microsoft_SqlServer_Dts_Runtime_Package_Members.htm
ms-help://MS.VSCC.v80/MS.VSIPCC.v80/MS.SQLSVR.v9.en/dtsref9mref/html/M_Microsoft_SqlServer_Dts_Runtime_Package_Execute.htm
-Jamie|||Also, please see the Books Online topic, "Running an Existing Package using Visual Basic."

-Doug|||

Is there any performance difference in running it from CLR and dtsui or command

vb code link:

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/dtsref9/html/2f9fc1a8-a001-4c54-8c64-63b443725422.htm

Dim app As New Application
Dim pkg As New Package
Dim pkgLocation As String
Dim pkgResults As DTSExecResult

pkgLocation = "C:\\Program Files\\Microsoft SQL Server\90\Samples\\Integration Services\\Package Samples\\CalculatedColumns Sample\\CalculatedColumns\\CalculatedColumns.dtsx"

pkg = app.LoadPackage(pkgLocation, Nothing, True)

pkgResults = pkg.Execute()

|||There might be some performance difference due to different reporting, but for most packages it is very small. It might be noticeable if you execute very fast tasks in a loop.

Designer UI and DtExecUI has some overhead to show the package progress and logging. Designer also executes package out-of-process to ensure designer stability, so it might be slower than other options.

DtExec speed depends on amount of logging and event reporting you turn on using command line.

Executing programmatically does not have any performance penalty.

In the code above please use
pkg = app.LoadPackage(pkgLocation, Nothing)
i.e. use two-argument version of LoadPackage method.

(If you pass True to three-argument version, you get neutral-threaded package COM object, which might be somewhat slower for execution. It is better and faster for package manipulation though).
|||

Is there an alternative LoadPackage method for when the Package is contained within the MSDB database vs. the File System?

Thanks

|||

Steve in Crystal Lake Illinios wrote:

Is there an alternative LoadPackage method for when the Package is contained within the MSDB database vs. the File System?

Thanks

Of course, see Application object documentation in Books Online. There are LoadFromSqlServer and LoadFromDtsServer methods.

|||

Is it possible to set this dtsx file to be scheduled from 6 am to 6 pm from monday to friday ?

Thanks a lot

|||

This is a snippet of code of our vb service:

"Fic" is when you have your dtsx allocated on Windows folder

"Sql" is allocated on MSDB

"dts" is allocated on SSIS Package Store (both Sql Server and Windows folder)

Select Case ObjSSIS.sSourceType

Case "Fic"
pkg = app.LoadPackage(ObjSSIS.sRutaDts & ObjSSIS.sSSISName & ".dtsx", Nothing, True)


Case "Sql"
pkg = app.LoadFromSqlServer(ObjSSIS.sRutaDts & ObjSSIS.sSSISName, ObjSSIS.sServer, Nothing, Nothing, Nothing)
Case "dts"
pkg = app.LoadFromDtsServer(ObjSSIS.sRutaDts & ObjSSIS.sSSISName, ObjSSIS.sServer, Nothing)
Case Else
Throw New ArgumentException("El paquete SSIS no tiene ubicación")
End Select

Execute SSIS package without SSIS console

Hello,

How can i do to execute SSIS package without SSIS console ?

This can occur when you use a hosted database with your hosted web.

thanksHi,
I'm not quite sure what you mean by the SSIS console.

Packages can be executed using DTExec - a command line execution tool. You can also execute packages from managed code.

Does this help?

-Jamie|||Do you mean that i can execute a dts package from an aspx web page ?

|||

Coroebus wrote:

Do you mean that i can execute a dts package from an aspx web page ?

Yes. Search this forum for clues.

You should use the Microsoft.SqlServer.ManagedDTS assembly

A few links:
ms-help://MS.VSCC.v80/MS.VSIPCC.v80/MS.SQLSVR.v9.en/dtsref9mref/html/T_Microsoft_SqlServer_Dts_Runtime_Package_Members.htm
ms-help://MS.VSCC.v80/MS.VSIPCC.v80/MS.SQLSVR.v9.en/dtsref9mref/html/M_Microsoft_SqlServer_Dts_Runtime_Package_Execute.htm
-Jamie|||Also, please see the Books Online topic, "Running an Existing Package using Visual Basic."

-Doug|||

Is there any performance difference in running it from CLR and dtsui or command

vb code link:

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/dtsref9/html/2f9fc1a8-a001-4c54-8c64-63b443725422.htm

Dim app As New Application
Dim pkg As New Package
Dim pkgLocation As String
Dim pkgResults As DTSExecResult

pkgLocation = "C:\\Program Files\\Microsoft SQL Server\90\Samples\\Integration Services\\Package Samples\\CalculatedColumns Sample\\CalculatedColumns\\CalculatedColumns.dtsx"

pkg = app.LoadPackage(pkgLocation, Nothing, True)

pkgResults = pkg.Execute()

|||There might be some performance difference due to different reporting, but for most packages it is very small. It might be noticeable if you execute very fast tasks in a loop.

Designer UI and DtExecUI has some overhead to show the package progress and logging. Designer also executes package out-of-process to ensure designer stability, so it might be slower than other options.

DtExec speed depends on amount of logging and event reporting you turn on using command line.

Executing programmatically does not have any performance penalty.

In the code above please use
pkg = app.LoadPackage(pkgLocation, Nothing)
i.e. use two-argument version of LoadPackage method.

(If you pass True to three-argument version, you get neutral-threaded package COM object, which might be somewhat slower for execution. It is better and faster for package manipulation though).
|||

Is there an alternative LoadPackage method for when the Package is contained within the MSDB database vs. the File System?

Thanks

|||

Steve in Crystal Lake Illinios wrote:

Is there an alternative LoadPackage method for when the Package is contained within the MSDB database vs. the File System?

Thanks

Of course, see Application object documentation in Books Online. There are LoadFromSqlServer and LoadFromDtsServer methods.

|||

Is it possible to set this dtsx file to be scheduled from 6 am to 6 pm from monday to friday ?

Thanks a lot

|||

This is a snippet of code of our vb service:

"Fic" is when you have your dtsx allocated on Windows folder

"Sql" is allocated on MSDB

"dts" is allocated on SSIS Package Store (both Sql Server and Windows folder)

Select Case ObjSSIS.sSourceType

Case "Fic"
pkg = app.LoadPackage(ObjSSIS.sRutaDts & ObjSSIS.sSSISName & ".dtsx", Nothing, True)


Case "Sql"
pkg = app.LoadFromSqlServer(ObjSSIS.sRutaDts & ObjSSIS.sSSISName, ObjSSIS.sServer, Nothing, Nothing, Nothing)
Case "dts"
pkg = app.LoadFromDtsServer(ObjSSIS.sRutaDts & ObjSSIS.sSSISName, ObjSSIS.sServer, Nothing)
Case Else
Throw New ArgumentException("El paquete SSIS no tiene ubicación")
End Select

Sunday, February 26, 2012

Execute Process Task / Console Output

I'm just starting to find my way around SSIS, coming from SQL 2000 DTS, but I can't see a way of including a Win32 Console application's output into the logging process.

I've started playing around with SSIS Logs (OnTaskFailed etc..), but I can find no where to allow me to capture the output from a console app. In SQL 2000 DTS I could capture this by specifying an "output file" on the advanced tab of the job step definition. Is there something as straight forward as this in SSIS ?

I'd be grateful for a few pointers in the right direction.

One way would be to pipe the console output to a text file using appropriate calling syntax (myconsoleapp.exe >> myoutput.txt) , then read it in via a flat file source in a following step. of course the console output might need to be structured or parsed in a way that meets your needs for the further processing of the data, but it's one way.

Ken

|||

Thanks for the suggestions Ken. I see where you are going with it, but it's not that I need to further process the output from console app's, just log what they are producing. In fact, they do already produce a flat file which mirrors the console output it's just that I'd like the whole output from the package to be in one place .

Under SQL 2000, the job steps manage to allow you to easily capture both the SQL server messages for tasks along with the output from an application. It seems that the logging in 2005 is much more complete and varied, but makes this simple task more complex to accomplish. I'm sure it can be done, I just don't know the best avenue for investigation. My last thought was to try using the StandardOutputVariable property on the execute process task to capture the data to a string. I haven't persued this as it seemed a bit of a long shot, but that's where I'm at.

|||Using StandardOutputVariable is not a long shot. Its a sure bet. Just use that variable, and in a subsequent Script task, call Dts.Events.FireInformation() using that variable as the message parameter.

Provided your logging options are set on the script task for the event type ("OnInformation") and for whatever log provider you choose, you can have the data in one place.|||

jaegd wrote:

Using StandardOutputVariable is not a long shot. Its a sure bet. Just use that variable, and in a subsequent Script task, call Dts.Events.FireInformation() using that variable as the message parameter.

Provided your logging options are set on the script task for the event type ("OnInformation") and for whatever log provider you choose, you can have the data in one place.

I just tried setting the StandardOutputVariable and StandardErrorVariable properties, and now the task pops up a window each time the process is executed (it's in a loop), even though I've also set the WindowStyle property to Hidden. Is that to be expected?

Execute Process Task / Console Output

I'm just starting to find my way around SSIS, coming from SQL 2000 DTS, but I can't see a way of including a Win32 Console application's output into the logging process.

I've started playing around with SSIS Logs (OnTaskFailed etc..), but I can find no where to allow me to capture the output from a console app. In SQL 2000 DTS I could capture this by specifying an "output file" on the advanced tab of the job step definition. Is there something as straight forward as this in SSIS ?

I'd be grateful for a few pointers in the right direction.

One way would be to pipe the console output to a text file using appropriate calling syntax (myconsoleapp.exe >> myoutput.txt) , then read it in via a flat file source in a following step. of course the console output might need to be structured or parsed in a way that meets your needs for the further processing of the data, but it's one way.

Ken

|||

Thanks for the suggestions Ken. I see where you are going with it, but it's not that I need to further process the output from console app's, just log what they are producing. In fact, they do already produce a flat file which mirrors the console output it's just that I'd like the whole output from the package to be in one place .

Under SQL 2000, the job steps manage to allow you to easily capture both the SQL server messages for tasks along with the output from an application. It seems that the logging in 2005 is much more complete and varied, but makes this simple task more complex to accomplish. I'm sure it can be done, I just don't know the best avenue for investigation. My last thought was to try using the StandardOutputVariable property on the execute process task to capture the data to a string. I haven't persued this as it seemed a bit of a long shot, but that's where I'm at.

|||Using StandardOutputVariable is not a long shot. Its a sure bet. Just use that variable, and in a subsequent Script task, call Dts.Events.FireInformation() using that variable as the message parameter.

Provided your logging options are set on the script task for the event type ("OnInformation") and for whatever log provider you choose, you can have the data in one place.|||

jaegd wrote:

Using StandardOutputVariable is not a long shot. Its a sure bet. Just use that variable, and in a subsequent Script task, call Dts.Events.FireInformation() using that variable as the message parameter.

Provided your logging options are set on the script task for the event type ("OnInformation") and for whatever log provider you choose, you can have the data in one place.

I just tried setting the StandardOutputVariable and StandardErrorVariable properties, and now the task pops up a window each time the process is executed (it's in a loop), even though I've also set the WindowStyle property to Hidden. Is that to be expected?