Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scheduled job fails

Status
Not open for further replies.

ramsfield

MIS
Jun 30, 2004
28
0
0
US
I have the following code in a store procedure. I have a scheduled job setup to run every half hour. The job fails everytime with no indication as to why. If I exec the stored procedure from query analzyer it runs just fine. However, when I run it as a scheduled job it fails. I have also tried running just the code from the stored proc from the job. It also fails. Any ideas why the job is failing, but runs fine from the analyzer?


CREATE PROCEDURE [sp_logged_in_users]

AS

Declare @record_time_2 [datetime]

Set @record_time_2 = Current_Timestamp

Begin

INSERT INTO
[Tidemark].[dbo].[logged_in_users]
( [Login_Name],[DBName], [LoginTime],[Lastbatch],[Record_time])

SELECT mp.loginame, ms.name,mp.login_time,mp.last_batch, @record_time_2
FROM master.dbo.sysprocesses mp INNER JOIN
master.dbo.sysdatabases ms ON mp.dbid = ms.dbid
WHERE (ms.name = N'Tidemark')and mp.loginame NOT IN ('sa','dbo','public')
End
GO
 
Check the job properties to see who the owner is and what SQL Server login the job is running under. I usually try and set my job owner to SA and set it to run as Self. The two currently set up in your job might be incompatible.



Catadmin - MCDBA, MCSA
"The only stupid question is the one that *wasn't* asked.
 
The job is owned by SA. The sql agent is started by a member of the sysadmin group.

The error is non-discript:

The job failed. The Job was invoked by User sa. The last step to run was step 1 (Logged_in_users).
 
Denis, yes, I just checked the database and it is set correctly. You are right about that, you never know. Its always good to double check.

I have even added this step to a job that runs fine, but it still fails. It kind of elimanates the job, but implicates the interaction between the agent the stored proc. ???
 
After overlooking the step history....

Executed as user: NT AUTHORITY\SYSTEM. String or binary data would be truncated. [SQLSTATE 22001] (Error 8152) The statement has been terminated. [SQLSTATE 01000] (Error 3621). The step failed.

I changed the field properties of one field of the destination table to match the system table and now it works fine.

Thanks for all the input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top