How to start a C# service using TSQL code - tsql

I use a C# service on Windows Server which stops from time to time. I'd like to write a stored procedure in TSQL to check if the service runs. If doesn't, I'd like to execute a procedure to restart it. Do you think it's doable using tsql? I've thought of xp_cmdshell but I don't know how to deal with it.

Related

Running stored procedure immediatelly

I'm currently in need to execute a stored procedure just before I load data into a table.
I've tried with a stored procedure activity but it still has a time (around 10 secs) to start the copy and it will interfere with other processes we have running.
Is there a faster way? I also looked at Azure functions but I dont think it should be that complicated.
The only way I can think of running it immediately before doing the actual copy is at the pre-copy script on the sink tab of the copy activity.
Any query you write there will be run before inserting the data, so if your database is a postgres (as you tagged the question) you may write:
Call functionName()
If it was a sql server:
exec functionName
Hope this helped!!

SQL Server guy working with PostgreSQL now, failing to create simple stored procedure - error Unterminated dollar quote

I am starting out with PostgreSQL and have realised that while working with C# and EF Core I have a set of logic that would work better in a stored procedure in the database. However I've come from a SQL Server background, so writing PL/pgSQL is a whole new ball game to me. I'm trying to create a test procedure below that just takes a string, adds some letters to it, and returns it. But it fails with the error shown in the screenshot. I can't really work out how to resolve this, or even what it's really pointing to. Can anyone assist?
Your (unspecified) client software is not hip to PostgreSQL syntax and thinks that the first best semicolon terminates a statement. Use something else.

Stored Procedure Fails on Converting Datetime Only When Ran From SQL Agent Job

Problem
Executed as user: CORP\SVC-UK-SVCEMI. Conversion failed when converting date and/or time from character string. [SQLSTATE 22007] (Error 241). The step failed.
The problem I am facing is that I have created a Stored Procedure which, when executing in a SSMS Query window, runs fine - but fails when ran ran from a SQL Agent job.
Why I'm Stuck
As the job is running the exact same procedure, on the same database and data, I am severely confused on why this wouldn't work.
My Thoughts
Logically, I would put it down to the user account (As this is the only possible different I had identified), thinking maybe the SQL Agent service account somehow has a difference date format setting when myself. However, I am under the impression that these are set at server level (Which we have recently changed to GB-English) - rather than account level.
As I can't manage to replicate this issue in the query window, it has become extremely difficult to debug which row is causing the issues
Running from SSMS Query Window
SQL Agent Jobstop Configuration
Error Generated When Running Job
As I believe this to be a SQL Agent configuration issue, I haven't added any code from the SQL Procedure. I can do this on request, but it is very long (Think I take readability over shortness - and possibly performance- when it comes to writing SQL)
Any ideas on what could be causing this problem would be greatly appreciated.
Many thanks.
Ths stored proc in the Job is probably running under a different user account than the one you use when launching it from SSIS.
and, probably, this user account has different settings
try "EXECUTE AS user=xxxx" for your stored proc and use your own user account, then see what happens...
see: EXECUTE AS

postgresql procedures/triggers

Is it possible to write a stored procedure or trigger that will be executed automatically inside of a database on particular time without any calls from application? If yes, then could anybody give me an example or link to some resource where I can read how to do that.
Check out pgAgent. If that doesn't work for you, there's always cron in Unix/Linux and the Task Scheduler service in Windows.
I don't think there's anything built-in, but you might want to check out
pgjobs or pgAgent.
You can use Stored Procedures. Stored Procedure is a set of statements, which allow ease and flexibility for a programmer because stored procedure is easy to execute than reissuing the number of individual SQL statements but they need to perform the same database operations.Using the stored procedure less information needs to be sent between the server and the client.
You can visit These links :-
Postgres Procedures
Best way to use stored Procedures

Progress ABL procedure to SQL Insert

We have a software solution that involves syncing some data between a Progress database and SQL server. Unfortunately, we do not have any Progress gurus in house, so I'm working kinda blind here and would welcome any advice that is on offer.
For the workflow that is already in place, what would work very well for us is the ability to do an external call to insert a row into an SQL database from an within ABL procedure's 'for each' loop.
Is anyone able to direct me to any code snippets or articles that might help me achieve this?
Many thanks,
In case your SQL database is MS SQL Server, you might want to have a look at OpenEdge DataServer for Microsoft SQL Server (web.progress.com/en/openedge/dataserver-microsoft.html, documentation.progress.com/output/OpenEdge102b/pdfs/dmsql/dmsql.pdf).
The DataServer provides you with ABL access to a non-Progress database so you can use standard Progress statements, e.g. CREATE to add new records or FOR EACH to retrieve query results.
OpenEdge DataServers are also available for Oracle (using Oracle Call Interface), DB2 and Sybase (using ODBC). The DataServer for MS SQL Server uses ODBC behind the scenes as well. web.progress.com/docs/datasheets/openedge/openedge_dataservers.pdf
You dont need the dataserver, connection with ADODB works fine in ABL, you can even call stored-procedures with the command object, the user you connect with will have to be granted EXEC rigths on the SQL-Server to do that.
I'm not a Progress guru, but I did do some work in it for awhile. AFAIK there is no way to have ABL code connect to a non-Progress database (part of that whole vendor lock-in strategy Progress Corp. leverages).
Your best bet is probably to have the ABL code serialize the records to XML, and use something like ActiveMQ (or even a plain socket or named pipe/FIFO depending on your setup) to send them to a program written in a more capable language to do the SQL insert.