SQL Server - JOB on server A executes file import to server B not working

Asked By Henry Taylor on 25-Nov-15 10:18 AM
I have a Scheduled Task running on server A that starts a c# console app.  That app calls a stored procedure (SP)  that does two things:

Step 1 - prepare a table to receive data by deleting stale records. This table is on server B
Step 2 - calls a JOB that imports a text file to the table on server B

If I run the stored procedure from SSMS under my account it works.

If the SP is called from c# code it will not work.  Step 1 of the SP works but when it gets to the call for the JOB it simply doesn't start the JOB and it gives no error.  Even in a BEGIN TRY CATCH there is no error.

This leads me to believe this is some kind of permissions issue but we are executing the Scheduled Task using a serveradmin account.  Shouldn't that account carry through and follow anything the app tries to do?

I hate the way these servers and databases are setup but I am powerless to fix that so I have to cross SQL Server instances with this.

Putting the JOB on the target instance is not an option due to various other factors - Doh!

Any ideas about why the JOB seems to be ignored in the SP when executed from c#?
Robbe Morris replied to Henry Taylor on 25-Nov-15 04:15 PM
What object inside the stored procedure is used to import the text file?

Is your connection string connecting to sql server via windows authentication or is it using sql authentication?

If it is a sql account, then you must grant appropriate access to it and that includes the ability to execute objects (like COM or .NET) that reside outside the stored procedure.
Henry Taylor replied to Robbe Morris on 30-Nov-15 08:46 AM
The file gets imported via a SSIS package (JOB).

The user account is a server admin account. That account is used to start the schedule task. The scheduled task starts the c# app. The c# app calls the stored procedures.  A stored procedure calls the SSIS package.

This all works fine on the development system.

The only change is on the the development system both databases used are on the same SQL instance.  A trusted connection is being used  in the connections strings.
Henry Taylor replied to Robbe Morris on 02-Dec-15 11:44 AM
I found out what the problem is here.

The SQL Server Agent appears to be running but it is not.  When SQL Server Agent is started it goes though it's own logon process. If anything goes wrong SQL Server Agent will still appear in SSMS as running with the Green arrow in the circle but it will not function properly.

Simply re-start SQL Server Agent. Doh! Two days wasted screwing around with this.