• I set up a user id called 'batchid' on a test server and created a logon trigger like this:

    CREATE TRIGGER usrLoginCheck_LogonTrigger

    ON ALL SERVER WITH EXECUTE AS 'batchid'

    FOR LOGON

    AS

    BEGIN

    declare @EarlyTime datetime,

    @LateTime datetime,

    @todays_date varchar(25)

    set @todays_date = CONVERT(varCHAR(25),GETDATE(),110)

    set @EarlyTime = Convert(datetime, @todays_date + ' 07:00:00.000')

    set @LateTime = Convert(datetime, @todays_date + ' 23:00:00.000')

    if ORIGINAL_LOGIN()= 'batchid'

    and getdate() between @EarlyTime and @LateTime

    ROLLBACK;

    END

    I tried to run an osql session to run a query from my desktop and it errored like I expected:

    Logon failed for login 'batchid' due to trigger execution.

    then I altered the trigger so the early time was after the current time (i.e. I was in the batch window and not during prime time) and the trigger allowed me to run the query.