Database field for T-SQL Job step

  • Hello,

    I am looking at some SQL Server Agent jobs which are running 'T-SQL script' steps. In this step, a stored procedure is being executed(command). Now, usually I would have seen some 'Database' mentioned in the 'Database' field. (Database context where to run this script). But in this case, database field is left blank. Job is running fine. Can anyone explain me how it works please.(Which database context it will take?).

    Thanks

    Regards,

    P

    ---------------------------------------------------------------------------------

  • I haven't really seen the database field being empty for T-SQL job steps. Even if you create a job via T-SQL commands and don't provide the @database value I think it picks up the user's default DB.

    Could you script out your job (go to SQL Server Agent->Jobs and right click on your job and choose Script job as -> Create To -> New Query Editor window). In that job script check for the particular step and see what the @database_name value is?

  • winash (8/21/2009)


    I haven't really seen the database field being empty for T-SQL job steps. Even if you create a job via T-SQL commands and don't provide the @database value I think it picks up the user's default DB.

    Could you script out your job (go to SQL Server Agent->Jobs and right click on your job and choose Script job as -> Create To -> New Query Editor window). In that job script check for the particular step and see what the @database_name value is?

    Thanks a lot Winash, for pointing me out in the right direction. Its strange but yes I can see the database name in the script,

    ..

    ..

    @database_name=N'MyDatabase'

    ..

    ..

    But the same is not visible in the windows(Database field)! Do you think its a bug or something? Thanks for your help again.

    ---------------------------------------------------------------------------------

  • I need more SQL field server. Can anyone help me? please inform me details.

    Cellulite Removal [/url]

  • It does look like a bug. There is a bug already logged on connect (http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=356617) that seems to be the same issue

  • winash (8/21/2009)


    It does look like a bug. There is a bug already logged on connect (http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=356617) that seems to be the same issue

    Thanks Winash, that was really helpful.

    I assume this is what happened in my case.

    The databases are generated dynamically and these jobs were created when that database did not actually exist. But when the job runs, this database will be created and online!

    So we could relate this to the behaviour that is explained in the connect link that u had given. Thanks again.

    Regards,

    P

    ---------------------------------------------------------------------------------

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply