Showing posts with label msg. Show all posts
Showing posts with label msg. Show all posts

Wednesday, March 21, 2012

Deadlock on a select query, possible?

I have a simple select query that selects data from a view. I consistently get a deadlock exception when running this query:

Server: Msg 1205, Level 13, State 2, Line 1
Transaction (Process ID #) was deadlocked on thread | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

The view is a simple select statement that has WITH (NOLOCK) as a hint on all tables. I thought I understand how deadlocks worked, two threads are holding a lock and request the other's item. How does a read uncommitted select statement participate in this?

If I look at the other processes in the current activity and run sql profiler, there is no other activity and no existing locks at the time the statement is run.

Can anyone explain this? Or should I bounce my server and hope it never happens again?

Thanks,

DaveAlthough the (NOLOCK) hint is puzzling, it is possible to deadlock on a single SELECT. I replicated this behavior about 12 years ago, but can't remember the specific scenario other than it was happening on a wide table (I think there was one row to a page, 2K pages) and the deadlock happened on the index.

To see where the deadlock is occuring, you may want to try:
Connection 1:
DBCC TraceOn(1204)
go

Begin Tran
Select foo From v_bar WITH (NOLOCK)
go

Connection 2 (immediately after executing 1)
Exec sp_lock
go

Check the errorlog to see the results of the trace and read up on Troubleshooting Deadlocks in SQL BOL.

Good luck.

Sunday, March 11, 2012

Deadlock

Hi All,
I need help urgently.
I got problem.
Whenever I issue DBCC SHRINKDATABASE the below message appear.
Server: Msg 1205, Level 13, State 57, Line 1
Transaction (Process ID 65) was deadlocked on lock resources with
another process and has been chosen as the deadlock victim. Rerun the
transaction.
I've tried to find out log transation by issue some command
sp_who,sp_who2,sp_lock,
SELECT spid, blocked, waittime
FROM sysprocesses
WHERE blocked <> 0
AND waittime > 10000
ORDER by waittime DESC
...
Yet It doesn't help me.
I found no deadlock process.
Could help me please?
Thanks, in advace, for helping me..
Regards,
Lux
*** Sent via Developersdex http://www.codecomments.com ***
It's known to happen sometimes. How to address it depends on
a few things. First, are you sure you actually need to
execute a shrink operation? Sometimes people start running
those and they really aren't necessary. Make sure you are
backing up your log as needed. You should check the
following article for more information:
http://www.karaszi.com/sqlserver/info_dont_shrink.asp
Also, if you really do need to do a shrink, try using dbcc
shrinkfile instead of shrinkdatabase so you have more
control over what files are being shrunk to what size. And
then if you are trying to shrink the data file...you may
want to try executing a DBCC INDEXDEFRAG which could help
when you then run a shrinkfile.
-Sue
On Mon, 22 Aug 2005 02:36:43 -0700, lux sok
<lux.lyny@.gmail.com> wrote:

>Hi All,
>I need help urgently.
>I got problem.
>Whenever I issue DBCC SHRINKDATABASE the below message appear.
>Server: Msg 1205, Level 13, State 57, Line 1
>Transaction (Process ID 65) was deadlocked on lock resources with
>another process and has been chosen as the deadlock victim. Rerun the
>transaction.
>I've tried to find out log transation by issue some command
>sp_who,sp_who2,sp_lock,
>SELECT spid, blocked, waittime
>FROM sysprocesses
>WHERE blocked <> 0
>AND waittime > 10000
>ORDER by waittime DESC
>...
>Yet It doesn't help me.
>I found no deadlock process.
>Could help me please?
>Thanks, in advace, for helping me..
>Regards,
>Lux
>
>*** Sent via Developersdex http://www.codecomments.com ***
|||Thanks, in advance, for helping me.
By the way, If i don't issue command DBCC SHRINKDATABASE/FILE do we have
any way to solve a logical file size grow ?
I mean when I droped/truncated a table the space remain the same
(logical file size).
For example, a table eat up 72GB when i dropped it.
I still can get this space back.
So my hard drive will full.
Any idea or comment please.
Maybe i'm not sure about the behind structure of MS SQLSERVER.
Thanks,
*** Sent via Developersdex http://www.codecomments.com ***
|||That should be a one time thing then right? You would use a
dbcc shrinkfile for that specifying the data file - that's
the file you are concerned about correct? The MDF?
Did you try dbcc shrinkfile?
If you get deadlocks, try the indexdefrag and then the
shrinkfile.
-Sue
On Tue, 23 Aug 2005 01:19:26 -0700, lux sok
<lux.lyny@.gmail.com> wrote:

>Thanks, in advance, for helping me.
>By the way, If i don't issue command DBCC SHRINKDATABASE/FILE do we have
>any way to solve a logical file size grow ?
>I mean when I droped/truncated a table the space remain the same
>(logical file size).
>For example, a table eat up 72GB when i dropped it.
>I still can get this space back.
>So my hard drive will full.
>Any idea or comment please.
>Maybe i'm not sure about the behind structure of MS SQLSERVER.
>Thanks,
>
>*** Sent via Developersdex http://www.codecomments.com ***

Thursday, March 8, 2012

Deadlock

Hi All,
I need help urgently.
I got problem.
Whenever I issue DBCC SHRINKDATABASE the below message appear.
Server: Msg 1205, Level 13, State 57, Line 1
Transaction (Process ID 65) was deadlocked on lock resources with
another process and has been chosen as the deadlock victim. Rerun the
transaction.
I've tried to find out log transation by issue some command
sp_who,sp_who2,sp_lock,
SELECT spid, blocked, waittime
FROM sysprocesses
WHERE blocked <> 0
AND waittime > 10000
ORDER by waittime DESC
...
Yet It doesn't help me.
I found no deadlock process.
Could help me please?
Thanks, in advace, for helping me..
Regards,
Lux
*** Sent via Developersdex http://www.codecomments.com ***It's known to happen sometimes. How to address it depends on
a few things. First, are you sure you actually need to
execute a shrink operation? Sometimes people start running
those and they really aren't necessary. Make sure you are
backing up your log as needed. You should check the
following article for more information:
http://www.karaszi.com/sqlserver/info_dont_shrink.asp
Also, if you really do need to do a shrink, try using dbcc
shrinkfile instead of shrinkdatabase so you have more
control over what files are being shrunk to what size. And
then if you are trying to shrink the data file...you may
want to try executing a DBCC INDEXDEFRAG which could help
when you then run a shrinkfile.
-Sue
On Mon, 22 Aug 2005 02:36:43 -0700, lux sok
<lux.lyny@.gmail.com> wrote:

>Hi All,
>I need help urgently.
>I got problem.
>Whenever I issue DBCC SHRINKDATABASE the below message appear.
>Server: Msg 1205, Level 13, State 57, Line 1
>Transaction (Process ID 65) was deadlocked on lock resources with
>another process and has been chosen as the deadlock victim. Rerun the
>transaction.
>I've tried to find out log transation by issue some command
>sp_who,sp_who2,sp_lock,
>SELECT spid, blocked, waittime
>FROM sysprocesses
>WHERE blocked <> 0
>AND waittime > 10000
>ORDER by waittime DESC
>...
>Yet It doesn't help me.
>I found no deadlock process.
>Could help me please?
>Thanks, in advace, for helping me..
>Regards,
>Lux
>
>*** Sent via Developersdex http://www.codecomments.com ***|||Thanks, in advance, for helping me.
By the way, If i don't issue command DBCC SHRINKDATABASE/FILE do we have
any way to solve a logical file size grow ?
I mean when I droped/truncated a table the space remain the same
(logical file size).
For example, a table eat up 72GB when i dropped it.
I still can get this space back.
So my hard drive will full.
Any idea or comment please.
Maybe i'm not sure about the behind structure of MS SQLSERVER.
Thanks,
*** Sent via Developersdex http://www.codecomments.com ***|||That should be a one time thing then right? You would use a
dbcc shrinkfile for that specifying the data file - that's
the file you are concerned about correct? The MDF?
Did you try dbcc shrinkfile?
If you get deadlocks, try the indexdefrag and then the
shrinkfile.
-Sue
On Tue, 23 Aug 2005 01:19:26 -0700, lux sok
<lux.lyny@.gmail.com> wrote:

>Thanks, in advance, for helping me.
>By the way, If i don't issue command DBCC SHRINKDATABASE/FILE do we have
>any way to solve a logical file size grow ?
>I mean when I droped/truncated a table the space remain the same
>(logical file size).
>For example, a table eat up 72GB when i dropped it.
>I still can get this space back.
>So my hard drive will full.
>Any idea or comment please.
>Maybe i'm not sure about the behind structure of MS SQLSERVER.
>Thanks,
>
>*** Sent via Developersdex http://www.codecomments.com ***

Wednesday, March 7, 2012

DDL Server Trigger Error (SQL2005)

I'm trying to create an 'ALL' Server DLL Trigger, as per BOL, but it's coming
up with the following error:
-----
Msg 1082, Level 15, State 1, Procedure trAll_ddl_server, Line 33
"DROP_SERVER_ROLE_MEMBER" does not support synchronous trigger registration.
-----
I've checked on the internet and have noted someone else having the same
problem, but with no resolution. Is this a bug? Has anyone a work-around?
Thanks.Hi
Can you post DDL to be tested?
"Pendragon999" <Pendragon999@.discussions.microsoft.com> wrote in message
news:A646F19B-B059-41F5-88FF-A290034AFDAD@.microsoft.com...
> I'm trying to create an 'ALL' Server DLL Trigger, as per BOL, but it's
> coming
> up with the following error:
> -----
> Msg 1082, Level 15, State 1, Procedure trAll_ddl_server, Line 33
> "DROP_SERVER_ROLE_MEMBER" does not support synchronous trigger
> registration.
> -----
> I've checked on the internet and have noted someone else having the same
> problem, but with no resolution. Is this a bug? Has anyone a work-around?
> Thanks.
>
>|||Hi Uri,
Here's the code (some bits removed for security):
CREATE TRIGGER trAll_ddl_server
ON ALL SERVER DDL_SERVER_LEVEL_EVENTS
AS
DECLARE @.eventData xml, @.eventID int
SET @.eventData = eventdata()
INSERT <AuditTbl> ( AuditEventObject, PostTime,
spid, LoginName, EventType, ServerName, DatabaseName, SchemaName,
ObjectName, TargetObjectName, TSQLCmd, ObjectType, EventData)
VALUES ('trAll_ddl_server',
cast(@.eventdata.query('data(//PostTime)') AS sysname),
cast(@.eventdata.query('data(//spid)') AS sysname),
cast(@.eventdata.query('data(//LoginName)') AS sysname),
cast(@.eventdata.query('data(//EventType)') AS sysname),
cast(@.eventdata.query('data(//ServerName)') AS sysname),
cast(@.eventdata.query('data(//DatabaseName)') AS sysname),
cast(@.eventdata.query('data(//SchemaName)') AS sysname),
cast(@.eventdata.query('data(//ObjectName)') AS sysname),
cast(@.eventdata.query('data(//TargetObjectName)') AS sysname),
cast(@.eventdata.query('data(//ObjectType)') AS sysname),
cast(@.eventdata.query('data(//TSQLCommand)') AS nvarchar(max)),
cast(@.eventdata.query('data(//EventData)') AS xml)
)
BEGIN
PRINT 'Permission denied. please contact the DBA.'
ROLLBACK
-- Set RolledBack flag
END
GO
/*
DISABLE TRIGGER trAll_ddl_server ON ALL SERVER
DROP TRIGGER trAll_ddl_server ON ALL SERVER
*/
"Uri Dimant" wrote:
> Hi
> Can you post DDL to be tested?
>
> "Pendragon999" <Pendragon999@.discussions.microsoft.com> wrote in message
> news:A646F19B-B059-41F5-88FF-A290034AFDAD@.microsoft.com...
> > I'm trying to create an 'ALL' Server DLL Trigger, as per BOL, but it's
> > coming
> > up with the following error:
> > -----
> > Msg 1082, Level 15, State 1, Procedure trAll_ddl_server, Line 33
> > "DROP_SERVER_ROLE_MEMBER" does not support synchronous trigger
> > registration.
> > -----
> >
> > I've checked on the internet and have noted someone else having the same
> > problem, but with no resolution. Is this a bug? Has anyone a work-around?
> >
> > Thanks.
> >
> >
> >
>
>|||Sorry, I've got the error
Msg 156, Level 15, State 1, Procedure trAll_ddl_server, Line 3
Incorrect syntax near the keyword 'AS'.
Msg 102, Level 15, State 1, Procedure trAll_ddl_server, Line 8
Incorrect syntax near '<'.
"Pendragon999" <Pendragon999@.discussions.microsoft.com> wrote in message
news:D494BCC9-0428-4486-B270-987210401878@.microsoft.com...
> Hi Uri,
> Here's the code (some bits removed for security):
> CREATE TRIGGER trAll_ddl_server
> ON ALL SERVER DDL_SERVER_LEVEL_EVENTS
> AS
> DECLARE @.eventData xml, @.eventID int
> SET @.eventData = eventdata()
> INSERT <AuditTbl> ( AuditEventObject, PostTime,
> spid, LoginName, EventType, ServerName, DatabaseName, SchemaName,
> ObjectName, TargetObjectName, TSQLCmd, ObjectType, EventData)
> VALUES ('trAll_ddl_server',
> cast(@.eventdata.query('data(//PostTime)') AS sysname),
> cast(@.eventdata.query('data(//spid)') AS sysname),
> cast(@.eventdata.query('data(//LoginName)') AS sysname),
> cast(@.eventdata.query('data(//EventType)') AS sysname),
> cast(@.eventdata.query('data(//ServerName)') AS sysname),
> cast(@.eventdata.query('data(//DatabaseName)') AS sysname),
> cast(@.eventdata.query('data(//SchemaName)') AS sysname),
> cast(@.eventdata.query('data(//ObjectName)') AS sysname),
> cast(@.eventdata.query('data(//TargetObjectName)') AS sysname),
> cast(@.eventdata.query('data(//ObjectType)') AS sysname),
> cast(@.eventdata.query('data(//TSQLCommand)') AS nvarchar(max)),
> cast(@.eventdata.query('data(//EventData)') AS xml)
> )
> BEGIN
> PRINT 'Permission denied. please contact the DBA.'
> ROLLBACK
> -- Set RolledBack flag
> END
> GO
> /*
> DISABLE TRIGGER trAll_ddl_server ON ALL SERVER
> DROP TRIGGER trAll_ddl_server ON ALL SERVER
> */
>
>
> "Uri Dimant" wrote:
>> Hi
>> Can you post DDL to be tested?
>>
>> "Pendragon999" <Pendragon999@.discussions.microsoft.com> wrote in message
>> news:A646F19B-B059-41F5-88FF-A290034AFDAD@.microsoft.com...
>> > I'm trying to create an 'ALL' Server DLL Trigger, as per BOL, but it's
>> > coming
>> > up with the following error:
>> > -----
>> > Msg 1082, Level 15, State 1, Procedure trAll_ddl_server, Line 33
>> > "DROP_SERVER_ROLE_MEMBER" does not support synchronous trigger
>> > registration.
>> > -----
>> >
>> > I've checked on the internet and have noted someone else having the
>> > same
>> > problem, but with no resolution. Is this a bug? Has anyone a
>> > work-around?
>> >
>> > Thanks.
>> >
>> >
>> >
>>|||Hi Uri,
I did say that some code had been taken out. Ok, here's some code that
should run as-is:
CREATE TRIGGER trig_All_ddl_database
ON DATABASE FOR
DDL_DATABASE_LEVEL_EVENTS
AS
PRINT 'Database DDL Trigger Fired.'
GO
"Uri Dimant" wrote:
> Sorry, I've got the error
> Msg 156, Level 15, State 1, Procedure trAll_ddl_server, Line 3
> Incorrect syntax near the keyword 'AS'.
> Msg 102, Level 15, State 1, Procedure trAll_ddl_server, Line 8
> Incorrect syntax near '<'.
>
>
>
> "Pendragon999" <Pendragon999@.discussions.microsoft.com> wrote in message
> news:D494BCC9-0428-4486-B270-987210401878@.microsoft.com...
> > Hi Uri,
> >
> > Here's the code (some bits removed for security):
> >
> > CREATE TRIGGER trAll_ddl_server
> > ON ALL SERVER DDL_SERVER_LEVEL_EVENTS
> > AS
> >
> > DECLARE @.eventData xml, @.eventID int
> > SET @.eventData = eventdata()
> >
> > INSERT <AuditTbl> ( AuditEventObject, PostTime,
> > spid, LoginName, EventType, ServerName, DatabaseName, SchemaName,
> > ObjectName, TargetObjectName, TSQLCmd, ObjectType, EventData)
> > VALUES ('trAll_ddl_server',
> > cast(@.eventdata.query('data(//PostTime)') AS sysname),
> > cast(@.eventdata.query('data(//spid)') AS sysname),
> > cast(@.eventdata.query('data(//LoginName)') AS sysname),
> > cast(@.eventdata.query('data(//EventType)') AS sysname),
> > cast(@.eventdata.query('data(//ServerName)') AS sysname),
> > cast(@.eventdata.query('data(//DatabaseName)') AS sysname),
> > cast(@.eventdata.query('data(//SchemaName)') AS sysname),
> > cast(@.eventdata.query('data(//ObjectName)') AS sysname),
> > cast(@.eventdata.query('data(//TargetObjectName)') AS sysname),
> > cast(@.eventdata.query('data(//ObjectType)') AS sysname),
> > cast(@.eventdata.query('data(//TSQLCommand)') AS nvarchar(max)),
> > cast(@.eventdata.query('data(//EventData)') AS xml)
> > )
> >
> > BEGIN
> > PRINT 'Permission denied. please contact the DBA.'
> > ROLLBACK
> > -- Set RolledBack flag
> > END
> > GO
> >
> > /*
> > DISABLE TRIGGER trAll_ddl_server ON ALL SERVER
> > DROP TRIGGER trAll_ddl_server ON ALL SERVER
> > */
> >
> >
> >
> >
> >
> > "Uri Dimant" wrote:
> >
> >> Hi
> >> Can you post DDL to be tested?
> >>
> >>
> >> "Pendragon999" <Pendragon999@.discussions.microsoft.com> wrote in message
> >> news:A646F19B-B059-41F5-88FF-A290034AFDAD@.microsoft.com...
> >> > I'm trying to create an 'ALL' Server DLL Trigger, as per BOL, but it's
> >> > coming
> >> > up with the following error:
> >> > -----
> >> > Msg 1082, Level 15, State 1, Procedure trAll_ddl_server, Line 33
> >> > "DROP_SERVER_ROLE_MEMBER" does not support synchronous trigger
> >> > registration.
> >> > -----
> >> >
> >> > I've checked on the internet and have noted someone else having the
> >> > same
> >> > problem, but with no resolution. Is this a bug? Has anyone a
> >> > work-around?
> >> >
> >> > Thanks.
> >> >
> >> >
> >> >
> >>
> >>
> >>
>
>

Friday, February 17, 2012

DBMail permission error

I am using DBMail to send an email notification at the completion of service broker process and have been getting the following security error:

Msg 229, Level 14, State 5, Procedure sp_send_dbmail, Line 1

EXECUTE permission denied on object 'sp_send_dbmail', database 'msdb', schema 'dbo'.

I have given the userID used to run the Service Broker, databasemailuserrole in msdb as per instruction in the msdb. I have also given it execute permission on the sp_send_dbmail but keep getting the error. The service broker is run using a sql login and the dbmail profile is set as public profile. Any suggestions would be much appreciated.

One thing you can do to find additional information on this error is to connect SQL Profiler and run a trace while redoing these steps. When you'll get the permission failure in the trace, you should find additional information telling you what the execution context was at that time. This should help you determine if you have granted EXECUTE permission to the proper principal. If things look as you expected in the trace, take a look at the catalogs as well, to see what permissions are granted on sp_send_mail.

Thanks
Laurentiu

|||

By 'service broker process' I assume you mean an activate procedure. In this case what happens is that you are hitting the 'Extending Database Impersonation under EXECUTE AS context' issue. See this blog entry at http://blogs.msdn.com/remusrusanu/archive/2006/01/12/512085.aspx

The solution is to either sign the activated procedure or mark the database as trustworthy.

HTH,
~ Remus

|||

Remus,

For test purposes, I assign guest to DatabaseMailUserRole in the msdb and I was able to receive the email successfully.

Can you clarify on your blog statement: "sign the procedure with a server level certificate that has the proper rights needed for the operation in question".

What I did were as follows:

1. create certificate with AUTHORIZATION of the user ID that has sysadmin server role (for testing purpose) in the database of the activated sproc

2. add signature to the activated sproc using the newly created certificate

3. add user ID from #1 to msdb and assign DatabaseMailuserRole role

When I run the service broker job, it still resulted in the permission error. Do I miss any steps ?

Many Thanks,

Welly

|||

You have not granted permissions to the certificate. Here's an example that shows how to sign a stored procedure and how to assign permissions to the signing certificate:

http://blogs.msdn.com/lcris/archive/2005/06/15/429631.aspx

The owner (who you specified in the AUTHORIZATION clause) does not matter for signing purposes. In your scenario, you would need to grant EXECUTE on sp_send_dbmail.

Thanks
Laurentiu