Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

sql job fails --- need help Expand / Collapse
Author
Message
Posted Wednesday, January 09, 2013 7:24 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 27, 2014 10:51 AM
Points: 112, Visits: 325
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
Post #1404778
Posted Wednesday, January 09, 2013 7:27 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, August 28, 2013 2:37 AM
Points: 5,075, Visits: 4,834
sp_dboption is a depreciated feature, user alter database instead

ALTER DATABASE myDB SET SINGLE_USER




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1404780
Posted Wednesday, January 09, 2013 7:30 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 27, 2014 10:51 AM
Points: 112, Visits: 325
anthony.green (1/9/2013)
sp_dboption is a depreciated feature, user alter database instead

ALTER 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
Post #1404783
Posted Wednesday, January 09, 2013 7:33 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, August 28, 2013 2:37 AM
Points: 5,075, Visits: 4,834
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




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1404785
Posted Wednesday, January 09, 2013 7:53 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 27, 2014 10:51 AM
Points: 112, Visits: 325
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)

Post #1404799
Posted Wednesday, January 09, 2013 7:55 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, August 28, 2013 2:37 AM
Points: 5,075, Visits: 4,834
ALTER DATABASE myDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1404800
Posted Wednesday, January 09, 2013 7:57 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 27, 2014 10:51 AM
Points: 112, Visits: 325
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.
Post #1404803
Posted Wednesday, January 09, 2013 7:58 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, August 28, 2013 2:37 AM
Points: 5,075, Visits: 4,834
The above will do exactly the same as what you are trying to do, just it is the new way of doing it.



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1404805
Posted Wednesday, January 09, 2013 8:09 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 27, 2014 10:51 AM
Points: 112, Visits: 325
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 ?

Post #1404814
Posted Wednesday, January 09, 2013 8:11 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, August 28, 2013 2:37 AM
Points: 5,075, Visits: 4,834
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





Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1404815
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse