January 9, 2013 at 7:24 am
Hello
I have one up and running job since few years but today i am facing one strange error.
here is error log
Executed as user: ABC\XYZ. Incorrect syntax near '*'. [SQLSTATE 42000] (Error 102). The step failed.
In that step there is no where '*'
here is command in the step
declare @spid varchar(2)
declare @execstat nvarchar(10)
declare kill_cursor cursor
for
select spid
from sysprocesses sp, sysdatabases sdb
where sp.dbid=sdb.dbid
and name='database_name'
open kill_cursor
Fetch next from kill_cursor into @spid
while (@@fetch_status =0)
Begin
set @execstat ='kill'+' '+@spid
exec sp_executesql @execstat
fetch next from kill_cursor into @spid
End
Close kill_cursor
deallocate kill_cursor
Please help me how to resolve.
Thanks
January 9, 2013 at 7:27 am
sp_dboption is a depreciated feature, user alter database instead
ALTER DATABASE myDB SET SINGLE_USER
January 9, 2013 at 7:30 am
anthony.green (1/9/2013)
sp_dboption is a depreciated feature, user alter database insteadALTER DATABASE myDB SET SINGLE_USER
Thanks for reply
It was my bad
actual script is as below
declare @spid varchar(2)
declare @execstat nvarchar(10)
declare kill_cursor cursor
for
select spid
from sysprocesses sp, sysdatabases sdb
where sp.dbid=sdb.dbid
and name='database_name'
open kill_cursor
Fetch next from kill_cursor into @spid
while (@@fetch_status =0)
Begin
set @execstat ='kill'+' '+@spid
exec sp_executesql @execstat
fetch next from kill_cursor into @spid
End
Close kill_cursor
deallocate kill_cursor
Please help me into this
January 9, 2013 at 7:33 am
What version of SQL are you running?
What is the purpose of the task at hand, do you just want to boot people out or are you setting the DB into single user mode?
sysprocesses and sysdatabases are also depreciated
January 9, 2013 at 7:53 am
anthony.green (1/9/2013)
What version of SQL are you running?What is the purpose of the task at hand, do you just want to boot people out or are you setting the DB into single user mode?
sysprocesses and sysdatabases are also depreciated
The purpose of task is , restore database
so first need to kill all spids for that database and then
change database into single user mode
so right now, job is failed to step-1(kill all spids)
January 9, 2013 at 7:55 am
ALTER DATABASE myDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
January 9, 2013 at 7:57 am
anthony.green (1/9/2013)
ALTER DATABASE myDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
Thank for Your reply
but job is failed to step-1 as killed spids
I need to resolve that.
January 9, 2013 at 7:58 am
The above will do exactly the same as what you are trying to do, just it is the new way of doing it.
January 9, 2013 at 8:09 am
anthony.green (1/9/2013)
The above will do exactly the same as what you are trying to do, just it is the new way of doing it.
so it means
ALTER DATABASE myDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
command will kill all spids as well as set database into SINGLE_USER ?
January 9, 2013 at 8:11 am
Yep that is correct.
ROLLBACK IMMEDIATE, will force any connections in that databases to stop executing and rollback what they where doing if they where in the middle of a transaction
SINGLE_USER does just what it says, after rollback, change DB to single user so that only 1 SPID can connect to it
January 9, 2013 at 8:14 am
anthony.green (1/9/2013)
Yep that is correct.ROLLBACK IMMEDIATE, will force any connections in that databases to stop executing and rollback what they where doing if they where in the middle of a transaction
SINGLE_USER does just what it says, after rollback, change DB to single user so that only 1 SPID can connect to it
That's Awesome
Thanks
so Now the process will finish in only one step, I don't need to do in step-1 and step-2 for kill all connections and set database to single user mode.
January 9, 2013 at 8:16 am
Ensure you do what you do in the same job step, no telling what may happen if it moves step and gets a different spid while its in single user mode not allowing you to access the DB as someone else beat you to it.
So
ALTER DATABASE myDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE myDB FROM DISK = 'xxxxxxxxxxxxxxxxxxxxxx'
GO
In the same job step.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply