Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 stop a transaction

Author  Topic 

missMac
Posting Yak Master

124 Posts

Posted - 2008-10-26 : 08:43:09
Hello,
I started a transaction in my db, but trying to stop it, but cant.

How do i check all running processes and kill that ID ?

I tried the following but doesnt work.

declare @transaction varchar(15)
set @transaction = 'processing'
kill @transaction;
go


Also tried

select @@spid

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-10-26 : 10:02:22
look up in BOL how to use KILL statement
it's "KILL spidNumber" not text

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-26 : 10:02:31
Maybe due to rollback. Run Sp_who2 and see state and kill the spid
Go to Top of Page

missMac
Posting Yak Master

124 Posts

Posted - 2008-10-26 : 20:49:36
quote:
Originally posted by spirit1

look up in BOL how to use KILL statement
it's "KILL spidNumber" not text

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!



I actually tried running your script, and it worked on the 1st db, which was a test, then i tried to run it on anotehr db, but it gives this error




(1 row(s) affected)
Msg 208, Level 16, State 72, Procedure usp_AddScheduledJob, Line 20
Invalid object name '//ScheduledJobService'.
Msg 208, Level 16, State 73, Procedure usp_AddScheduledJob, Line 20
Invalid object name '//ScheduledJobContract'.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-26 : 22:22:24
You aren't showing us the full code that you ran.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-10-27 : 05:24:44
from your code i see you're using my scheduled job for sql express example.
this error means you don't have those services in the database you're running this on.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

missMac
Posting Yak Master

124 Posts

Posted - 2008-10-27 : 06:21:50
quote:
Originally posted by spirit1

from your code i see you're using my scheduled job for sql express example.
this error means you don't have those services in the database you're running this on.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!




I ran the statement alter database [example_test] set enable_broker

and it said it was ok.
Go to Top of Page

missMac
Posting Yak Master

124 Posts

Posted - 2008-10-27 : 06:23:18
Or how do i enable them ?
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-10-27 : 06:29:01
If you are still trying to find the pid of the job you can use this in a query analyser window. It's a noddy little script (and I'm sure could be better but should allow you to find the pid).

Then just do a KILL <pid>


/* Jobs Details for a specific db (works on 2000 and 2005)
**
** Charlie (19/02/2008)
** Modified (11/06/2008)
*/

-- ==== Configuration =========================================================

DECLARE @dbName VARCHAR(50) SET @dbName = '<NAME OF DATABASE HERE>'

-- ==== ------------- =========================================================

USE MASTER
SET NOCOUNT ON

IF object_Id('tempdb..#spwho') IS NOT NULL DROP TABLE #spwho
IF object_Id('tempdb..#info') IS NOT NULL DROP TABLE #info
IF object_Id('tempdb..#dbccInput') IS NOT NULL DROP TABLE #dbccInput

DECLARE
@spid INT
, @sqlHandle BINARY(20)
, @sqlVersion INT

-- Which version of SQL server are we running.
SET @sqlVersion = CASE
WHEN @@VERSION LIKE '%2005 - 9.%' THEN 2005
WHEN @@VERSION LIKE '%2000 - 8.%' THEN 2000
END

CREATE TABLE #spWho (
[SPID] INT NOT NULL
, [Status] VARCHAR (255) NOT NULL
, [Login] VARCHAR (255) NOT NULL
, [HostName] VARCHAR (255) NOT NULL
, [BlkBy] VARCHAR(10) NOT NULL
, [DBName] VARCHAR (255) NULL
, [Command] VARCHAR (255) NOT NULL
, [CPUTime] INT NOT NULL
, [DiskIO] INT NOT NULL
, [LastBatch] VARCHAR (255) NOT NULL
, [ProgramName] VARCHAR (255) NOT NULL
, [SPID2] INT NOT NULL
)

-- Add a column if it's 2005
IF @sqlVersion = 2005 ALTER TABLE #spWho ADD [REQUESTID] INT NOT NULL DEFAULT 0

CREATE TABLE #dbccInput (
eventType NVARCHAR(30)
, paramaters INT
, eventInfo NVARCHAR(4000)
)

CREATE TABLE #info (
[spid] INT NOT NULL
, [status] VARCHAR(20) NOT NULL
, [login] VARCHAR(255) NOT NULL
, [blkBy] VARCHAR(10) NOT NULL
, [command] VARCHAR(255) NOT NULL
, [CPUTime] INT NOT NULL
, [DiskIO] INT NOT NULL
, [LastBatch] VARCHAR (255) NOT NULL
, [ProgramName] VARCHAR (255) NOT NULL
, [sqlHandle] BINARY(20) NULL
, [eventInfo] NVARCHAR(4000) NULL
, [sql] TEXT NULL
)

INSERT INTO #spWho EXEC sp_who2

-- Get basic job info for the database we are intersted in
INSERT INTO #info (
[spid]
, [status]
, [login]
, [blkBy]
, [command]
, [CPUTime]
, [DiskIO]
, [LastBatch]
, [ProgramName]
, [sqlHandle]
)
SELECT
sw.[spid]
, sw.[status]
, sw.[login]
, sw.[blkBy]
, sw.[command]
, sw.[CPUTime]
, sw.[diskIO]
, sw.[lastBatch]
, sw.[programName]
, sp.[sql_handle]
FROM
#spWho sw
JOIN master.dbo.sysprocesses sp ON sp.[spid] = sw.[spid]
WHERE
[DBName] = @dbName

-- Get the sql info for each spid
DECLARE sqlCursor CURSOR LOCAL READ_ONLY FOR
SELECT
i.[spid]
, i.[sqlHandle]
FROM
#info i

OPEN sqlCursor

FETCH NEXT FROM sqlCursor INTO
@spid
, @sqlHandle

WHILE (@@fetch_status = 0) BEGIN

INSERT INTO #dbccInput
EXEC ('DBCC INPUTBUFFER(' + @spid + ')')

UPDATE #info
SET
[eventInfo] = dbccI.[eventInfo]
FROM
#dbccInput dbccI
WHERE
[spid] = @spid

-- clear the input info
TRUNCATE TABLE #dbccInput

-- Get the sql full text (only does currently running process)
UPDATE #info
SET
[sql] = fgs.[text]
FROM
::fn_get_sql(@sqlHandle) fgs
WHERE
[spid] = @spid

FETCH NEXT FROM sqlCursor INTO
@spid
, @sqlHandle

END

CLOSE sqlCursor
DEALLOCATE sqlCursor

-- Display the results
SELECT
[spid]
, [status]
, [login]
, [blkBy]
, [command]
, [CPUTime]
, [DiskIO]
, [LastBatch]
, [ProgramName]
, [eventInfo] AS lastEvent
, [sql] AS currentSql
FROM
#info

IF object_Id('tempdb..#spwho') IS NOT NULL DROP TABLE #spwho
IF object_Id('tempdb..#info') IS NOT NULL DROP TABLE #info
IF object_Id('tempdb..#dbccInput') IS NOT NULL DROP TABLE #dbccInput


-------------
Charlie
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-10-27 : 07:15:25
quote:
Originally posted by missMac

Or how do i enable them ?



you don't reenable them. you have to create them!


_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

missMac
Posting Yak Master

124 Posts

Posted - 2008-10-27 : 07:36:54
quote:
Originally posted by spirit1

quote:
Originally posted by missMac

Or how do i enable them ?



you don't reenable them. you have to create them!


_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!



1. how please ?


I ran the statement alter database [example_test] set enable_broker

and it said it was ok.

2. How do i check which services are up and running ? sp_who2 ?

am using your script and trying to run it, but its not running the add_job ???

Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-10-27 : 08:13:33
well first you have to know what service broker objects are and how they work.
i suggest you read this to understand what's needed:
http://www.sqlteam.com/article/centralized-asynchronous-auditing-with-service-broker

before we have a base common ground level of SB understanding there's no way to help you.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

missMac
Posting Yak Master

124 Posts

Posted - 2008-10-27 : 09:06:51
Thanks, I have read it. But the article does not say how to enable it ?

Please help
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-10-27 : 09:10:42
enable what??
you enable the service broker but you create its objects.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page
   

- Advertisement -