Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Tuesday, March 27, 2012

Executing exe delphi program with Agent

Hi,
I'm trying to execute a program from de agent. The program executes(i can see it in the task manager), but it block in that step and still in the task manager.
I tried with the calc.exe command with de same result.
?only DOS commands can execute the agent or there is another way to make it work?
Thanks in advance
Lomu
Hi
If the program shows a GUI then you should not run it from a scheduled job.
If you make it a command line program that will run and exit correctly then
you may be ok. Depending on what you are wanting to do there could be other
alternatives, such as writing an extended stored procedure, making it a COM
object.
John
"Lomu" <Lomu@.discussions.microsoft.com> wrote in message
news:BCDDC329-81E3-457E-90E4-3C38A830AF92@.microsoft.com...
> Hi,
> I'm trying to execute a program from de agent. The program executes(i can
see it in the task manager), but it block in that step and still in the task
manager.
> I tried with the calc.exe command with de same result.
> only DOS commands can execute the agent or there is another way to make
it work?
> Thanks in advance
> Lomu

Executing exe delphi program with Agent

Hi,
I'm trying to execute a program from de agent. The program executes(i can see it in the task manager), but it block in that step and still in the task manager.
I tried with the calc.exe command with de same result.
¿only DOS commands can execute the agent or there is another way to make it work?
Thanks in advance
LomuHi
If the program shows a GUI then you should not run it from a scheduled job.
If you make it a command line program that will run and exit correctly then
you may be ok. Depending on what you are wanting to do there could be other
alternatives, such as writing an extended stored procedure, making it a COM
object.
John
"Lomu" <Lomu@.discussions.microsoft.com> wrote in message
news:BCDDC329-81E3-457E-90E4-3C38A830AF92@.microsoft.com...
> Hi,
> I'm trying to execute a program from de agent. The program executes(i can
see it in the task manager), but it block in that step and still in the task
manager.
> I tried with the calc.exe command with de same result.
> ¿only DOS commands can execute the agent or there is another way to make
it work?
> Thanks in advance
> Lomu

Executing exe delphi program with Agent

Hi,
I'm trying to execute a program from de agent. The program executes(i can se
e it in the task manager), but it block in that step and still in the task m
anager.
I tried with the calc.exe command with de same result.
?only DOS commands can execute the agent or there is another way to make it
work?
Thanks in advance
LomuHi
If the program shows a GUI then you should not run it from a scheduled job.
If you make it a command line program that will run and exit correctly then
you may be ok. Depending on what you are wanting to do there could be other
alternatives, such as writing an extended stored procedure, making it a COM
object.
John
"Lomu" <Lomu@.discussions.microsoft.com> wrote in message
news:BCDDC329-81E3-457E-90E4-3C38A830AF92@.microsoft.com...
> Hi,
> I'm trying to execute a program from de agent. The program executes(i can
see it in the task manager), but it block in that step and still in the task
manager.
> I tried with the calc.exe command with de same result.
> only DOS commands can execute the agent or there is another way to make
it work?
> Thanks in advance
> Lomu

Friday, March 23, 2012

Executing a package from within a C# program returns failure everytime

Hi All,

I am trying to execute a package (programmatically) that is stored on my local disk using the information that is provided on the following page:

http://msdn2.microsoft.com/en-us/library/ms136090.aspx

This means, I am using the Application object and the Package object to actually load the package using the path to it.

So my code looks something like this:

--

pkgLocation = @."<package_path>/Package1.dtsx";

app = new Application();

pkg = app.LoadPackage(pkgLocation, null);

pkgResults = pkg.Execute();

Console.WriteLine(pkgResults.ToString());

Console.ReadKey();

My package reads in a flat file (located on another server) and transforms it and saves it to a database (on that same server). And mind you, I can execute this package just fine when I do it manually from within BIDS.

But when I try to execute the above mentioned code in my C# solution (compiled to a command line executable), I always get a "Failure".

Can somebody point out what I am doing wrong here?

Thank you in advance,

Manan Pancholi

You can use the following code to get the errors after execution

foreach (DtsError dtserr in pkg.Errors)
{
Console.WriteLine("Source: " + dtserr.Source + ", Description: " + dtserr.Description);
}|||

Thanks Kaarthik,

I believe I have narrowed down the problem. It seems that unless the Integration Services are installed on my machine, I would not be able to execute some tasks that are part of the package that I am calling programmatically. Atleast thats what the error information pointed out to me.

I believe that the authentication works differently when I am trying to execute the package manually and when I am trying to execute the package in my C# code. This is kind of odd, but thanks again for the help.

I will follow this up with a detailed example of how to execute a package programmatically and what sort of permissions would one need when working with remote sources and destinations.

Manan Pancholi

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 statement?

Hi,
I have an ADO component in a delphi program that I use to check a database
for structure changes that are needed. This is basically just a long list o
f
SQL statements. In one instance I need to add a new field if it doesn't
exist, then update the field with values from another field. When I execute
the code, the program says it can't find the new field. If I take the updat
e
statement out it runs fine. Is there a way to either have the alter command
execute before the update command runs? If this were query analyzer I'd jus
t
use the 'GO' statement, is there an equivalent statement I could use? Here
is the SQL statements I'm using:
if not exists (SELECT *
FROM SYSCOLUMNS
WHERE ID = OBJECT_ID('MYTABLE')
AND Name = 'NEWFIELD'
)
begin
alter table mytable
add [NEWFIELD] nvarchar(7);
/* this statement below is what is failing */
update mytable set NEWFIELD=OLDFIELD where IsNull(OldField,'') <> '';
end;Two roundtrips, the first one to create the column and the second one to
update if everything was ok. Your application can also call OSQL utility to
execute a batch file.
AMB
"Thread77" wrote:

> Hi,
> I have an ADO component in a delphi program that I use to check a database
> for structure changes that are needed. This is basically just a long list
of
> SQL statements. In one instance I need to add a new field if it doesn't
> exist, then update the field with values from another field. When I execu
te
> the code, the program says it can't find the new field. If I take the upd
ate
> statement out it runs fine. Is there a way to either have the alter comma
nd
> execute before the update command runs? If this were query analyzer I'd j
ust
> use the 'GO' statement, is there an equivalent statement I could use? Her
e
> is the SQL statements I'm using:
> if not exists (SELECT *
> FROM SYSCOLUMNS
> WHERE ID = OBJECT_ID('MYTABLE')
> AND Name = 'NEWFIELD'
> )
> begin
> alter table mytable
> add [NEWFIELD] nvarchar(7);
> /* this statement below is what is failing */
> update mytable set NEWFIELD=OLDFIELD where IsNull(OldField,'') <> '';
> end;|||You can just do what ISQL is doing. Break up your batches (on the same
connection) on a GO (you will have to add it to your query) and send two
distinct commands to the server.
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"Thread77" <Thread77@.discussions.microsoft.com> wrote in message
news:E2FA4078-BEDC-4D9F-BB35-75A9289E6EC0@.microsoft.com...
> Hi,
> I have an ADO component in a delphi program that I use to check a database
> for structure changes that are needed. This is basically just a long list
> of
> SQL statements. In one instance I need to add a new field if it doesn't
> exist, then update the field with values from another field. When I
> execute
> the code, the program says it can't find the new field. If I take the
> update
> statement out it runs fine. Is there a way to either have the alter
> command
> execute before the update command runs? If this were query analyzer I'd
> just
> use the 'GO' statement, is there an equivalent statement I could use?
> Here
> is the SQL statements I'm using:
> if not exists (SELECT *
> FROM SYSCOLUMNS
> WHERE ID = OBJECT_ID('MYTABLE')
> AND Name = 'NEWFIELD'
> )
> begin
> alter table mytable
> add [NEWFIELD] nvarchar(7);
> /* this statement below is what is failing */
> update mytable set NEWFIELD=OLDFIELD where IsNull(OldField,'') <> '';
> end;

Wednesday, March 7, 2012

Execute Program with Time Delay

Hi
I would like to execute a program from an SQL Server Proceedure.
But I need to Execute it with a 3 minute time delay, plus if there is
another instance of this delayed execute running then I need to not add
another.
Any help would be much appreciated
Thanks
BTry this
WAITFOR DELAY '00:03:00"
Madhivanan|||Synchronous or asynchronous?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Ben" <Ben@.NoSpam.com> wrote in message news:%23wVcch9HFHA.3608@.TK2MSFTNGP14.phx.gbl...[col
or=darkred]
> Hi
> I would like to execute a program from an SQL Server Proceedure.
> But I need to Execute it with a 3 minute time delay, plus if there is anot
her instance of this
> delayed execute running then I need to not add another.
> Any help would be much appreciated
> Thanks
> B
>[/color]|||Hi Tibor
Asynchronous, as I would like the user to continue working, in ignorance of
the delay/execution of the application.
Thanks
B
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OHzPo99HFHA.1172@.TK2MSFTNGP12.phx.gbl...
> Synchronous or asynchronous?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Ben" <Ben@.NoSpam.com> wrote in message
> news:%23wVcch9HFHA.3608@.TK2MSFTNGP14.phx.gbl...
>|||You can, from the stored procedure, create or just schedule a SQL Server Age
nt job. See Books Online
for things as sp_add_job etc. You need to put in some code for the checking
whether the job is
already "on queue". Agent will not execute a job is it is already executing
(will not have two
instances of the same job executing at the same time), so perhaps this is su
fficient for you?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Ben" <Ben@.NoSpam.com> wrote in message news:e2m4wF%23HFHA.3484@.TK2MSFTNGP12.phx.gbl...[col
or=darkred]
> Hi Tibor
> Asynchronous, as I would like the user to continue working, in ignorance o
f the delay/execution of
> the application.
> Thanks
> B
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote i
n message
> news:OHzPo99HFHA.1172@.TK2MSFTNGP12.phx.gbl...
>[/color]