Showing posts with label hii. Show all posts
Showing posts with label hii. Show all posts

Thursday, March 29, 2012

deadlocks in sql server

Hi
I'm having a problem with deadlocks in a table in SQL server when
trying to update it through Biztalk 2004. There is no problem when I
use the same Biztalk solution to update a similar dummy table, but
when I try updating the original table in the production database,
some transactions are updated successfully whereas others become the
victim of the deadlock (Transaction (Process ID 185) was deadlocked on
lock resources with another process and has been chosen as the
deadlock victim. Rerun the transaction). The table that is updated is
also being used by another application that just selects rows from it.

As a workaround, I have used recursion in the code that updates the
table. The function is put through a recursive loop whenever the
deadlock exception(#1205) is caught. It keeps on trying to update the
table until the updation is successful or another exception (not the
deadlock one) is caught. i.e.

Bool Update_IVR(string amount, string customer_id)
{
Try
{
//updation code
}
}
Catch (exception ex)
{
If( ex.message == deadlock message)
{
Bool succ =Update_IVR (amount, customer_id) //recursion
Return succ;
}
Else //error handling code
}

After introducing this code, the problem did not occur for the next
13000 transactions. Then I got the error again four times along with a
timeout error (Timeout expired. The timeout period elapsed prior to
completion of the operation or the server is not responding). However
for the next 17000 transactions (to date) this error has not showed
up.

Thanks

HasanHasan (hasan@.mobilink.net) writes:
> I'm having a problem with deadlocks in a table in SQL server when
> trying to update it through Biztalk 2004. There is no problem when I
> use the same Biztalk solution to update a similar dummy table, but
> when I try updating the original table in the production database,
> some transactions are updated successfully whereas others become the
> victim of the deadlock (Transaction (Process ID 185) was deadlocked on
> lock resources with another process and has been chosen as the
> deadlock victim. Rerun the transaction). The table that is updated is
> also being used by another application that just selects rows from it.
> As a workaround, I have used recursion in the code that updates the
> table. The function is put through a recursive loop whenever the
> deadlock exception(#1205) is caught. It keeps on trying to update the
> table until the updation is successful or another exception (not the
> deadlock one) is caught. i.e.
>...
> After introducing this code, the problem did not occur for the next
> 13000 transactions. Then I got the error again four times along with a
> timeout error (Timeout expired. The timeout period elapsed prior to
> completion of the operation or the server is not responding). However
> for the next 17000 transactions (to date) this error has not showed
> up.

It seems that you have locking problems in your application, and you
need to perform further analysis to find out where the problem might lie.

Deadlock happens when two processes is trying to access resources already
locked by the other. Here is a simple example:

BEGIN TRANSACTION BEGIN TRANSACTION
UPDATE tbla UPDATE tblb
SET col = 12 SET col = 98
WHERE keycol = 1 WHERE keycol = 8

UPDATE tblb UPDATE tbla
SET col = 88 SET col = 546
WHERE keycol = 8 WHERE keycol = 1
COMMIT TRANSACTION COMMIT TRANSACTION

This will deadlock, when the two processes come to their second UPDATE
statement, they will wait for each other. SQL Server detects this
situation and select one as a deadlock victim.

"Timeout expired" on the other hand can have many causes. This is a timeout
which is set up by the client library, and of which SQL Server has no
knowledge. A timeout could elapse because of long processing time, but
also because the process is blocked by another process. Important to
know is that when you get an timeout expired, you should probably submit
a "IF @.@.trancount > 0 ROLLBACK TRANSACTION", because there is no automatic
rollback in this case.

I would assume that in your case the Timeout Expired was due to blocking.

In order to understand the cause of deadlocks, you need to get more
information. One way is to set up a Profiler trace to catch deadlocks.
You can also enable trace flags 1204 and 3605 by adding -T1204 and -T3605
to the startup parameters in Enterprise Manger, and restart SQL Server.
In this case, each deadlock will be logged in the SQL Server error log.
In fairly cryptic manner, but neverless.

To detect blocking and what the involved processes are doing, I have a
stored procedure, which is good for this. It's called aba_lockinfo and
you find it on http://www.sommarskog.se/sqlutil/aba_lockinfo.html.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||
Thanks for your reply. I have a better understadning of whats going on
now. Can you please explain to me how to set the trace flags you've
mentioned.

Thanks
Hasan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Hasan Sheikh (hasan@.mobilink.net) writes:
> Thanks for your reply. I have a better understadning of whats going on
> now. Can you please explain to me how to set the trace flags you've
> mentioned.

As I said:

You can also enable trace flags 1204 and 3605 by adding -T1204 and -T3605
to the startup parameters in Enterprise Manger, and restart SQL Server

To get there, right-click the server in EM, select Properties. Startup
Parameters is a button at the buttom of the General tab.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.aspsql

Tuesday, March 27, 2012

Deadlocks "again"

Hi
I am getting the same deadlock on our SQL 2K server but with different SPID
Ids throughout the day.
I know what tables and Index information from the KEY: information , and
that is it performing an exclusive lock. What i cannot figure out is what
to do to help resolve this.
Do anyone have any tips? Here is the deadlock results: -
Deadlock encountered ... Printing deadlock information
Wait-for graph
Node:1
KEY: 6:1618820829:1 (7d009bbca7e6) CleanCnt:2 Mode: X Flags: 0x0
Grant List 1::
Owner:0x51983760 Mode: X Flg:0x0 Ref:1 Life:02000000 SPID:64 ECID:0
SPID: 64 ECID: 0 Statement Type: UPDATE Line #: 136
Input Buf: RPC Event: sp_execute;1
Requested By:
ResType:LockOwner Stype:'OR' Mode: Range-S-U SPID:61 ECID:0 Ec0x77D6D550)
Value:0x46951760 Cost0/F08)
Node:2
KEY: 6:1831013604:1 (0c0021774e53) CleanCnt:2 Mode: X Flags: 0x0
Grant List 2::
Owner:0x2faa6340 Mode: X Flg:0x0 Ref:2 Life:02000000 SPID:61 ECID:0
SPID: 61 ECID: 0 Statement Type: SELECT Line #: 1
Input Buf: RPC Event: sp_execute;1
Requested By:
ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
Value:0x51983620 Cost0/714)
Victim Resource Owner:
ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
Value:0x51983620 Cost0/714)
Many Thanks
Hi Hush
Have you identified the SQL statements that cause the deadlock and tried to
optimize the queries/indexes so that the locks resolve faster. The dump
specify the RPC event as sp_execute,1. Are you executing dynamic SQL ?
Regards
Charl
http://www.sqlserver.co.za
"Hush" wrote:

> Hi
> I am getting the same deadlock on our SQL 2K server but with different SPID
> Ids throughout the day.
> I know what tables and Index information from the KEY: information , and
> that is it performing an exclusive lock. What i cannot figure out is what
> to do to help resolve this.
> Do anyone have any tips? Here is the deadlock results: -
> Deadlock encountered ... Printing deadlock information
> Wait-for graph
> Node:1
> KEY: 6:1618820829:1 (7d009bbca7e6) CleanCnt:2 Mode: X Flags: 0x0
> Grant List 1::
> Owner:0x51983760 Mode: X Flg:0x0 Ref:1 Life:02000000 SPID:64 ECID:0
> SPID: 64 ECID: 0 Statement Type: UPDATE Line #: 136
> Input Buf: RPC Event: sp_execute;1
> Requested By:
> ResType:LockOwner Stype:'OR' Mode: Range-S-U SPID:61 ECID:0 Ec0x77D6D550)
> Value:0x46951760 Cost0/F08)
> Node:2
> KEY: 6:1831013604:1 (0c0021774e53) CleanCnt:2 Mode: X Flags: 0x0
> Grant List 2::
> Owner:0x2faa6340 Mode: X Flg:0x0 Ref:2 Life:02000000 SPID:61 ECID:0
> SPID: 61 ECID: 0 Statement Type: SELECT Line #: 1
> Input Buf: RPC Event: sp_execute;1
> Requested By:
> ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
> Value:0x51983620 Cost0/714)
> Victim Resource Owner:
> ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
> Value:0x51983620 Cost0/714)
>
> Many Thanks
>
>
|||See if these help:
http://msdn.microsoft.com/library/de...tabse_5xrn.asp
Troubleshooting Deadlocks
http://www.support.microsoft.com/?id=224453 Blocking Problems
http://www.support.microsoft.com/?id=271509 How to monitor SQL 2000
Blocking
Andrew J. Kelly SQL MVP
"Hush" <hushdontspamme@.hotmail.com> wrote in message
news:uzWvhdOSGHA.5156@.TK2MSFTNGP10.phx.gbl...
> Hi
> I am getting the same deadlock on our SQL 2K server but with different
> SPID Ids throughout the day.
> I know what tables and Index information from the KEY: information , and
> that is it performing an exclusive lock. What i cannot figure out is what
> to do to help resolve this.
> Do anyone have any tips? Here is the deadlock results: -
> Deadlock encountered ... Printing deadlock information
> Wait-for graph
> Node:1
> KEY: 6:1618820829:1 (7d009bbca7e6) CleanCnt:2 Mode: X Flags: 0x0
> Grant List 1::
> Owner:0x51983760 Mode: X Flg:0x0 Ref:1 Life:02000000 SPID:64 ECID:0
> SPID: 64 ECID: 0 Statement Type: UPDATE Line #: 136
> Input Buf: RPC Event: sp_execute;1
> Requested By:
> ResType:LockOwner Stype:'OR' Mode: Range-S-U SPID:61 ECID:0
> Ec0x77D6D550) Value:0x46951760 Cost0/F08)
> Node:2
> KEY: 6:1831013604:1 (0c0021774e53) CleanCnt:2 Mode: X Flags: 0x0
> Grant List 2::
> Owner:0x2faa6340 Mode: X Flg:0x0 Ref:2 Life:02000000 SPID:61 ECID:0
> SPID: 61 ECID: 0 Statement Type: SELECT Line #: 1
> Input Buf: RPC Event: sp_execute;1
> Requested By:
> ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
> Value:0x51983620 Cost0/714)
> Victim Resource Owner:
> ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
> Value:0x51983620 Cost0/714)
>
> Many Thanks
>
|||Hi Charl
Thanks for your reply:
I am currently running a SQL Profiler - How do i look for the RPC event? I
have included Excution Plan and the SQL locks events in the profiler.
What i am alittle concerned about is that the table in question has on index
(Clustered Index) and out of the 7 Columns in the table 6 of them is
assigned to clustered index. Is that good practice?
I am a non SQL Developer DBA....so i am a little stuck with this.
Many Thanks
"Charl" <Charl@.discussions.microsoft.com> wrote in message
news:F38AA9E6-F580-4F62-A3D6-93C70375D145@.microsoft.com...[vbcol=seagreen]
> Hi Hush
> Have you identified the SQL statements that cause the deadlock and tried
> to
> optimize the queries/indexes so that the locks resolve faster. The dump
> specify the RPC event as sp_execute,1. Are you executing dynamic SQL ?
> Regards
> Charl
> --
> http://www.sqlserver.co.za
>
> "Hush" wrote:
|||While there are always exceptions having that many columns in a clustered
index is usually not a good idea. Since the leaf level of the clustered
index is the actual data there is little to gain by clustering on so many
columns. Usually you can make the index selective enough on just a few and
it is always a good idea to keep the clustered index narrow since the
clustered index key is appended to the end of any nonclustered indexes as
well. If you are updating any of the 6 columns in the clustered index there
is a prime candidate for deadlocks since it has to physically move the
entire row.
Andrew J. Kelly SQL MVP
"Hush" <hushdontspamme@.hotmail.com> wrote in message
news:ekTgocPSGHA.424@.TK2MSFTNGP12.phx.gbl...
> Hi Charl
> Thanks for your reply:
> I am currently running a SQL Profiler - How do i look for the RPC event?
> I have included Excution Plan and the SQL locks events in the profiler.
> What i am alittle concerned about is that the table in question has on
> index (Clustered Index) and out of the 7 Columns in the table 6 of them is
> assigned to clustered index. Is that good practice?
> I am a non SQL Developer DBA....so i am a little stuck with this.
> Many Thanks
>
> "Charl" <Charl@.discussions.microsoft.com> wrote in message
> news:F38AA9E6-F580-4F62-A3D6-93C70375D145@.microsoft.com...
>

Deadlocks "again"

Hi
I am getting the same deadlock on our SQL 2K server but with different SPID
Ids throughout the day.
I know what tables and Index information from the KEY: information , and
that is it performing an exclusive lock. What i cannot figure out is what
to do to help resolve this.
Do anyone have any tips? Here is the deadlock results: -
Deadlock encountered ... Printing deadlock information
Wait-for graph
Node:1
KEY: 6:1618820829:1 (7d009bbca7e6) CleanCnt:2 Mode: X Flags: 0x0
Grant List 1::
Owner:0x51983760 Mode: X Flg:0x0 Ref:1 Life:02000000 SPID:64 ECID:0
SPID: 64 ECID: 0 Statement Type: UPDATE Line #: 136
Input Buf: RPC Event: sp_execute;1
Requested By:
ResType:LockOwner Stype:'OR' Mode: Range-S-U SPID:61 ECID:0 Ec0x77D6D550)
Value:0x46951760 Cost0/F08)
Node:2
KEY: 6:1831013604:1 (0c0021774e53) CleanCnt:2 Mode: X Flags: 0x0
Grant List 2::
Owner:0x2faa6340 Mode: X Flg:0x0 Ref:2 Life:02000000 SPID:61 ECID:0
SPID: 61 ECID: 0 Statement Type: SELECT Line #: 1
Input Buf: RPC Event: sp_execute;1
Requested By:
ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
Value:0x51983620 Cost0/714)
Victim Resource Owner:
ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
Value:0x51983620 Cost0/714)
Many ThanksHi Hush
Have you identified the SQL statements that cause the deadlock and tried to
optimize the queries/indexes so that the locks resolve faster. The dump
specify the RPC event as sp_execute,1. Are you executing dynamic SQL ?
Regards
Charl
http://www.sqlserver.co.za
"Hush" wrote:

> Hi
> I am getting the same deadlock on our SQL 2K server but with different SPI
D
> Ids throughout the day.
> I know what tables and Index information from the KEY: information , and
> that is it performing an exclusive lock. What i cannot figure out is what
> to do to help resolve this.
> Do anyone have any tips? Here is the deadlock results: -
> Deadlock encountered ... Printing deadlock information
> Wait-for graph
> Node:1
> KEY: 6:1618820829:1 (7d009bbca7e6) CleanCnt:2 Mode: X Flags: 0x0
> Grant List 1::
> Owner:0x51983760 Mode: X Flg:0x0 Ref:1 Life:02000000 SPID:64 ECID:0
> SPID: 64 ECID: 0 Statement Type: UPDATE Line #: 136
> Input Buf: RPC Event: sp_execute;1
> Requested By:
> ResType:LockOwner Stype:'OR' Mode: Range-S-U SPID:61 ECID:0 Ec0x77D6D550
)
> Value:0x46951760 Cost0/F08)
> Node:2
> KEY: 6:1831013604:1 (0c0021774e53) CleanCnt:2 Mode: X Flags: 0x0
> Grant List 2::
> Owner:0x2faa6340 Mode: X Flg:0x0 Ref:2 Life:02000000 SPID:61 ECID:0
> SPID: 61 ECID: 0 Statement Type: SELECT Line #: 1
> Input Buf: RPC Event: sp_execute;1
> Requested By:
> ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
> Value:0x51983620 Cost0/714)
> Victim Resource Owner:
> ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
> Value:0x51983620 Cost0/714)
>
> Many Thanks
>
>|||See if these help:
http://msdn.microsoft.com/library/d...
tabse_5xrn.asp
Troubleshooting Deadlocks
http://www.support.microsoft.com/?id=224453 Blocking Problems
http://www.support.microsoft.com/?id=271509 How to monitor SQL 2000
Blocking
Andrew J. Kelly SQL MVP
"Hush" <hushdontspamme@.hotmail.com> wrote in message
news:uzWvhdOSGHA.5156@.TK2MSFTNGP10.phx.gbl...
> Hi
> I am getting the same deadlock on our SQL 2K server but with different
> SPID Ids throughout the day.
> I know what tables and Index information from the KEY: information , and
> that is it performing an exclusive lock. What i cannot figure out is what
> to do to help resolve this.
> Do anyone have any tips? Here is the deadlock results: -
> Deadlock encountered ... Printing deadlock information
> Wait-for graph
> Node:1
> KEY: 6:1618820829:1 (7d009bbca7e6) CleanCnt:2 Mode: X Flags: 0x0
> Grant List 1::
> Owner:0x51983760 Mode: X Flg:0x0 Ref:1 Life:02000000 SPID:64 ECID:0
> SPID: 64 ECID: 0 Statement Type: UPDATE Line #: 136
> Input Buf: RPC Event: sp_execute;1
> Requested By:
> ResType:LockOwner Stype:'OR' Mode: Range-S-U SPID:61 ECID:0
> Ec0x77D6D550) Value:0x46951760 Cost0/F08)
> Node:2
> KEY: 6:1831013604:1 (0c0021774e53) CleanCnt:2 Mode: X Flags: 0x0
> Grant List 2::
> Owner:0x2faa6340 Mode: X Flg:0x0 Ref:2 Life:02000000 SPID:61 ECID:0
> SPID: 61 ECID: 0 Statement Type: SELECT Line #: 1
> Input Buf: RPC Event: sp_execute;1
> Requested By:
> ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
> Value:0x51983620 Cost0/714)
> Victim Resource Owner:
> ResType:LockOwner Stype:'OR' Mode: X SPID:64 ECID:0 Ec0x7E9EF550)
> Value:0x51983620 Cost0/714)
>
> Many Thanks
>|||Hi Charl
Thanks for your reply:
I am currently running a SQL Profiler - How do i look for the RPC event? I
have included Excution Plan and the SQL locks events in the profiler.
What i am alittle concerned about is that the table in question has on index
(Clustered Index) and out of the 7 Columns in the table 6 of them is
assigned to clustered index. Is that good practice?
I am a non SQL Developer DBA....so i am a little stuck with this.
Many Thanks
"Charl" <Charl@.discussions.microsoft.com> wrote in message
news:F38AA9E6-F580-4F62-A3D6-93C70375D145@.microsoft.com...[vbcol=seagreen]
> Hi Hush
> Have you identified the SQL statements that cause the deadlock and tried
> to
> optimize the queries/indexes so that the locks resolve faster. The dump
> specify the RPC event as sp_execute,1. Are you executing dynamic SQL ?
> Regards
> Charl
> --
> http://www.sqlserver.co.za
>
> "Hush" wrote:
>|||While there are always exceptions having that many columns in a clustered
index is usually not a good idea. Since the leaf level of the clustered
index is the actual data there is little to gain by clustering on so many
columns. Usually you can make the index selective enough on just a few and
it is always a good idea to keep the clustered index narrow since the
clustered index key is appended to the end of any nonclustered indexes as
well. If you are updating any of the 6 columns in the clustered index there
is a prime candidate for deadlocks since it has to physically move the
entire row.
Andrew J. Kelly SQL MVP
"Hush" <hushdontspamme@.hotmail.com> wrote in message
news:ekTgocPSGHA.424@.TK2MSFTNGP12.phx.gbl...
> Hi Charl
> Thanks for your reply:
> I am currently running a SQL Profiler - How do i look for the RPC event?
> I have included Excution Plan and the SQL locks events in the profiler.
> What i am alittle concerned about is that the table in question has on
> index (Clustered Index) and out of the 7 Columns in the table 6 of them is
> assigned to clustered index. Is that good practice?
> I am a non SQL Developer DBA....so i am a little stuck with this.
> Many Thanks
>
> "Charl" <Charl@.discussions.microsoft.com> wrote in message
> news:F38AA9E6-F580-4F62-A3D6-93C70375D145@.microsoft.com...
>

DEADLOCKS

Hi:
I have a .net web application and I am getting a lot of deadlocks. My
system processes a lot of real-time transactions daily. In addition ,
there are like 3 DTS packages running. The problem is that I am getting a
lot of deadlock and based on the history of the pakages I would say that is
happening because the packages take the control and kill the processes that
are tying to run at the same time.
Is there a way to try to reduce this dead-lock assigning especific features
to the packages.
ThanksI don't think there are any issues specific to DTS packages that cause
deadlocking. A package could be excuting almost anything, so provide more
details about what type of selects / updates / inserts the package is
performing and also the nature of the transactions that are being blocked.
Read up in Books Online about "set transaction isolation level". Consider
using a lower isolation level, like read uncommitted. Basically, this allows
a process to read data currently locked by another transaction. Just
understand what "dirty reads", "nonrepeatable reads", etc. are and whether
or not they would present a significant problem in the specific case of your
queries.
Also, for what it's worth, here are my bookmarks for SQL Server deadlocking:
Deadlocking
http://msdn.microsoft.com/library/d... />
a_8i93.asp
INF: Analyzing and Avoiding Deadlocks in SQL Server
http://support.microsoft.com/defaul...kb;en-us;169960
Tracing Deadlocks
http://www.sqlservercentral.com/col...ngdeadlocks.asp
Minimizing Deadlocks
http://msdn.microsoft.com/library/d... />
a_3hdf.asp
SQL Server technical bulletin - How to resolve a deadlock
http://support.microsoft.com/defaul...kb;en-us;832524
"Gina Hernandez" <pdwhitt@.nospam.wdsinc.com> wrote in message
news:%23OfWoX19FHA.4004@.TK2MSFTNGP14.phx.gbl...
> Hi:
> I have a .net web application and I am getting a lot of deadlocks. My
> system processes a lot of real-time transactions daily. In addition ,
> there are like 3 DTS packages running. The problem is that I am getting
> a lot of deadlock and based on the history of the pakages I would say that
> is happening because the packages take the control and kill the processes
> that are tying to run at the same time.
> Is there a way to try to reduce this dead-lock assigning especific
> features to the packages.
> Thanks
>

Monday, March 19, 2012

Deadlock in SQL 2000

Hi
I think you don't need wrap the script BEGIN TRAN ...COMMIT because the tran
asction is atomic by itself
"Hongbo" <hongbo@.goodoffices.com> wrote in message news:ezJRDs6lFHA.1372@.TK2
MSFTNGP10.phx.gbl...
Hi,
I have 2 update statements in SQL Server 2000:
1. with TRAN
==
BEGIN TRAN UpdateProductShipFlag
UPDATE ProductToOrder
SET ShippedFlag=1, ShippedDate=getdate()
WHERE ProductToOrderId=500603
COMMIT TRAN UpdateProductShipFlag
==
2. without TRAN
==
UPDATE ProductToOrder
SET ShippedFlag=1, ShippedDate=getdate()
WHERE ProductToOrderId=500603
==
I got "deadlock" error with first statement.
I do not use locking hints in any of my SQL statements.
Would you please tell me the difference between the above 2 statements
on lock level?
Thank you
HBAlso, it takes 2 SPIDs to deadlock. Where's the other SPID? What T-SQL
is the other SPID executing? What locks are involved in the deadlock?
etc. etc. Lots of questions that need to be asked to resolve your issue.
But to answer your question, there is no difference between those 2
statements on a lock level - as Uri said the update statement is atomic
on it's own so the scope of any locks involved in that statement are the
same with or without the explicit BEGIN/COMMIT and the BEING/COMMIT pair
don't change the type of locks involved or the resources locked.
*mike hodgson*
blog: http://sqlnerd.blogspot.com
Uri Dimant wrote:

> Hi
> I think you don't need wrap the script BEGIN TRAN ...COMMIT because
> the tranasction is atomic by itself
>
> "Hongbo" <hongbo@.goodoffices.com <mailto:hongbo@.goodoffices.com>>
> wrote in message news:ezJRDs6lFHA.1372@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I have 2 update statements in SQL Server 2000:
> 1. with TRAN
> ==
> BEGIN TRAN UpdateProductShipFlag
> UPDATE ProductToOrder
> SET ShippedFlag=1, ShippedDate=getdate()
> WHERE ProductToOrderId=500603
> COMMIT TRAN UpdateProductShipFlag
> ==
> 2. without TRAN
> ==
> UPDATE ProductToOrder
> SET ShippedFlag=1, ShippedDate=getdate()
> WHERE ProductToOrderId=500603
> ==
> I got "deadlock" error with first statement.
> I do not use locking hints in any of my SQL statements.
> Would you please tell me the difference between the above 2 statements
> on lock level?
> Thank you
> HB
>|||Uri and Mike,
Thank you for the help!
"Mike Hodgson" <mike.hodgson@.mallesons.nospam.com> wrote in message news:uA0
26l$lFHA.4056@.TK2MSFTNGP10.phx.gbl...
Also, it takes 2 SPIDs to deadlock. Where's the other SPID? What T-SQL is
the other SPID executing? What locks are involved in the deadlock? etc. et
c. Lots of questions that need to be asked to resolve your issue.
But to answer your question, there is no difference between those 2 statemen
ts on a lock level - as Uri said the update statement is atomic on it's own
so the scope of any locks involved in that statement are the same with or wi
thout the explicit BEGIN/COMMIT and the BEING/COMMIT pair don't change the t
ype of locks involved or the resources locked.
mike hodgson
blog: http://sqlnerd.blogspot.com
Uri Dimant wrote:
Hi
I think you don't need wrap the script BEGIN TRAN ...COMMIT because the tra
nasction is atomic by itself
"Hongbo" <hongbo@.goodoffices.com> wrote in message news:ezJRDs6lFHA.1372@.TK2
MSFTNGP10.phx.gbl...
Hi,
I have 2 update statements in SQL Server 2000:
1. with TRAN
==
BEGIN TRAN UpdateProductShipFlag
UPDATE ProductToOrder
SET ShippedFlag=1, ShippedDate=getdate()
WHERE ProductToOrderId=500603
COMMIT TRAN UpdateProductShipFlag
==
2. without TRAN
==
UPDATE ProductToOrder
SET ShippedFlag=1, ShippedDate=getdate()
WHERE ProductToOrderId=500603
==
I got "deadlock" error with first statement.
I do not use locking hints in any of my SQL statements.
Would you please tell me the difference between the above 2 statements
on lock level?
Thank you
HB

Saturday, February 25, 2012

DBs islolated in the middle of the ocean

Hi
I'm about to begin development on an application that manages information on
15 ships. The ships are standardized on Win NT 4.0, no new hardware is per
missable, the DB can't run as a server and no technical staff will ever be a
vailable to administer it.
Strange requirements, but that's what they are. Does this force me into som
thing like Access and Jet? The ship data (about 5000 records per month) mus
t replicate over satellite with a central office DB--which can run SQL Serve
r. Any suggestions on how
to design this?
Thanks
GavinAccess might be the best choice, because if something goes wrong you can
just get a new database file over there that you create from the data at the
central office. I assume that the people on board of the ship are computer
literate enough to copy a file in the right location, so they can fix the
problem themselves. If the DB can't run as a service, that pretty much rules
out SQL Server and most other DBMS's. 5000 rows per month is within the
limits of Access. I assume bandwith is at a premium, so exchanging zipped
text files might be a better option than using replication for example. Just
look at technology that was around 5-8 years ago and use that :-)
Jacco Schalkwijk
SQL Server MVP
"Gavin" <gavin@.nospam.nospam> wrote in message
news:9F43B591-A45A-4CEA-8CB1-A998FDEB918F@.microsoft.com...
> Hi
> I'm about to begin development on an application that manages information
on 15 ships. The ships are standardized on Win NT 4.0, no new hardware is
permissable, the DB can't run as a server and no technical staff will ever
be available to administer it. Strange requirements, but that's what they
are. Does this force me into somthing like Access and Jet? The ship data
(about 5000 records per month) must replicate over satellite with a central
office DB--which can run SQL Server. Any suggestions on how to design this?
> Thanks
> Gavin
>|||What does "can't run as a server" mean?
And what's going to happen if they get a disc failure or other hardware
issue? (which, I assume, will be much more likely at sea than in a nice
climate controlled hosting area, in which hardware failures occur all the
time!)
"Gavin" <gavin@.nospam.nospam> wrote in message
news:9F43B591-A45A-4CEA-8CB1-A998FDEB918F@.microsoft.com...
> Hi
> I'm about to begin development on an application that manages information
on 15 ships. The ships are standardized on Win NT 4.0, no new hardware is
permissable, the DB can't run as a server and no technical staff will ever
be available to administer it. Strange requirements, but that's what they
are. Does this force me into somthing like Access and Jet? The ship data
(about 5000 records per month) must replicate over satellite with a central
office DB--which can run SQL Server. Any suggestions on how to design this?
> Thanks
> Gavin
>|||Use sql desktop edition - (MSDE) - it's free and is essentially sql server w
ith limits - it will run on any pc - the pc doesn't have to be a server - do
a backup each evening - compress the backup.
Email the backup via satellite to head office and restore to main server - a
ll of this can be automated...
MSDE will be much more robust and reliable than access - access can break yo
ur heart sometimes...
Jim.

Sunday, February 19, 2012

dbo question

Hi
I can see that in some of our databases, the user 'dbo' are mapped to a
specific loginname where in others it's not mapped to anything. How can I
change this so the 'dbo' user isn't mapped to a specific useraccount. The
reason is that I'd like to remove the login that's set as 'dbo' for those
databases.
I've looked in BOL, but I'm not quite sure about the steps to perform to get
this fixed. I know that all members of the Sysadmin role is mapped to 'dbo'
so that's what I'd like to have rather than mapping a specific user to the
'dbo' user.
Since it's in our production environment is has to be changed, I'd like to
be fairly sure about the steps to do before I just go ahead and change
it...;-)
Regards
SteenHello Steen,
You can use sp_changedbowner like this:
use <mydb>
exec sp_changedbowner 'sa'
This will map the sa login to dbo user in the mydb database. Why do you want
to remove the dbo user?
Mark.

> Hi
> I can see that in some of our databases, the user 'dbo' are mapped to
> a specific loginname where in others it's not mapped to anything. How
> can I change this so the 'dbo' user isn't mapped to a specific
> useraccount. The reason is that I'd like to remove the login that's
> set as 'dbo' for those databases.
> I've looked in BOL, but I'm not quite sure about the steps to perform
> to get this fixed. I know that all members of the Sysadmin role is
> mapped to 'dbo' so that's what I'd like to have rather than mapping a
> specific user to the 'dbo' user.
> Since it's in our production environment is has to be changed, I'd
> like to be fairly sure about the steps to do before I just go ahead
> and change it...;-)
> Regards
> Steen|||Hi Mark
The reason for removing this specific dbo user, is because we are trying to
"clean up" our SQL server installations. We have 8 servers for various
applications and there haven't really been any corporate guidelines for how
to install them. They are therefore installed and configured in different
ways.
As I understand the sp_changedbowner, it will map the username spcified to
the dbo role, but I'm not sure that's what I want.
If I look at some of the other SQLServers, it looks like no specific
loginname has been mapped to 'dbo'. In this case I assume that dbo is the
loginnames which are members of the System Administrators Role on the
server. I don't know if this scenario is advisable or not, but would it be
possible to remove the dbo mapping to a specific loginname and change it to
a "blank" loginname?
/Steen
Mark Allison wrote:[vbcol=seagreen]
> Hello Steen,
> You can use sp_changedbowner like this:
> use <mydb>
> exec sp_changedbowner 'sa'
> This will map the sa login to dbo user in the mydb database. Why do
> you want to remove the dbo user?
> Mark.
>|||dbo is always mapped to something. It is safe to map all of them to sa or
some other login you expect will always exist... I use either sa or a
trusted login so moving databases arouns isn't quite so much trouble.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Steen Persson" <SPE@.REMOVEdatea.dk> wrote in message
news:u36YSpI$EHA.612@.TK2MSFTNGP09.phx.gbl...
> Hi Mark
> The reason for removing this specific dbo user, is because we are trying
to
> "clean up" our SQL server installations. We have 8 servers for various
> applications and there haven't really been any corporate guidelines for
how
> to install them. They are therefore installed and configured in different
> ways.
> As I understand the sp_changedbowner, it will map the username spcified to
> the dbo role, but I'm not sure that's what I want.
> If I look at some of the other SQLServers, it looks like no specific
> loginname has been mapped to 'dbo'. In this case I assume that dbo is the
> loginnames which are members of the System Administrators Role on the
> server. I don't know if this scenario is advisable or not, but would it be
> possible to remove the dbo mapping to a specific loginname and change it
to
> a "blank" loginname?
> /Steen
>
> Mark Allison wrote:
>|||Thanks Wayne,
I investigated it a little bit further, and I think I found out what
confused me. When I look at the dbo user for a database in EM, it shows no
Login Name. If I then look at the same db in QA (sp_helpdb) it shows the
owner ok.
The cases where EM doesn't show a login name, seems to be the ones where the
dbo isn't mapped to a login name that has been created as a login in SQL
but is a user that's member of the SystemAdministrator role (and/or in the
local admin groups on the server). This might be obvious and clear for
others, but it confused me a little bit...;-).
Thanks for your inputs.
Regards
Steen
Wayne Snyder wrote:[vbcol=seagreen]
> dbo is always mapped to something. It is safe to map all of them to
> sa or some other login you expect will always exist... I use either
> sa or a trusted login so moving databases arouns isn't quite so much
> trouble.
>
> "Steen Persson" <SPE@.REMOVEdatea.dk> wrote in message
> news:u36YSpI$EHA.612@.TK2MSFTNGP09.phx.gbl...

dbo question

Hi
I can see that in some of our databases, the user 'dbo' are mapped to a
specific loginname where in others it's not mapped to anything. How can I
change this so the 'dbo' user isn't mapped to a specific useraccount. The
reason is that I'd like to remove the login that's set as 'dbo' for those
databases.
I've looked in BOL, but I'm not quite sure about the steps to perform to get
this fixed. I know that all members of the Sysadmin role is mapped to 'dbo'
so that's what I'd like to have rather than mapping a specific user to the
'dbo' user.
Since it's in our production environment is has to be changed, I'd like to
be fairly sure about the steps to do before I just go ahead and change
it...;-)
Regards
Steen
Hello Steen,
You can use sp_changedbowner like this:
use <mydb>
exec sp_changedbowner 'sa'
This will map the sa login to dbo user in the mydb database. Why do you want
to remove the dbo user?
Mark.

> Hi
> I can see that in some of our databases, the user 'dbo' are mapped to
> a specific loginname where in others it's not mapped to anything. How
> can I change this so the 'dbo' user isn't mapped to a specific
> useraccount. The reason is that I'd like to remove the login that's
> set as 'dbo' for those databases.
> I've looked in BOL, but I'm not quite sure about the steps to perform
> to get this fixed. I know that all members of the Sysadmin role is
> mapped to 'dbo' so that's what I'd like to have rather than mapping a
> specific user to the 'dbo' user.
> Since it's in our production environment is has to be changed, I'd
> like to be fairly sure about the steps to do before I just go ahead
> and change it...;-)
> Regards
> Steen
|||Hi Mark
The reason for removing this specific dbo user, is because we are trying to
"clean up" our SQL server installations. We have 8 servers for various
applications and there haven't really been any corporate guidelines for how
to install them. They are therefore installed and configured in different
ways.
As I understand the sp_changedbowner, it will map the username spcified to
the dbo role, but I'm not sure that's what I want.
If I look at some of the other SQLServers, it looks like no specific
loginname has been mapped to 'dbo'. In this case I assume that dbo is the
loginnames which are members of the System Administrators Role on the
server. I don't know if this scenario is advisable or not, but would it be
possible to remove the dbo mapping to a specific loginname and change it to
a "blank" loginname?
/Steen
Mark Allison wrote:[vbcol=seagreen]
> Hello Steen,
> You can use sp_changedbowner like this:
> use <mydb>
> exec sp_changedbowner 'sa'
> This will map the sa login to dbo user in the mydb database. Why do
> you want to remove the dbo user?
> Mark.
>
|||dbo is always mapped to something. It is safe to map all of them to sa or
some other login you expect will always exist... I use either sa or a
trusted login so moving databases arouns isn't quite so much trouble.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Steen Persson" <SPE@.REMOVEdatea.dk> wrote in message
news:u36YSpI$EHA.612@.TK2MSFTNGP09.phx.gbl...
> Hi Mark
> The reason for removing this specific dbo user, is because we are trying
to
> "clean up" our SQL server installations. We have 8 servers for various
> applications and there haven't really been any corporate guidelines for
how
> to install them. They are therefore installed and configured in different
> ways.
> As I understand the sp_changedbowner, it will map the username spcified to
> the dbo role, but I'm not sure that's what I want.
> If I look at some of the other SQLServers, it looks like no specific
> loginname has been mapped to 'dbo'. In this case I assume that dbo is the
> loginnames which are members of the System Administrators Role on the
> server. I don't know if this scenario is advisable or not, but would it be
> possible to remove the dbo mapping to a specific loginname and change it
to
> a "blank" loginname?
> /Steen
>
> Mark Allison wrote:
>
|||Thanks Wayne,
I investigated it a little bit further, and I think I found out what
confused me. When I look at the dbo user for a database in EM, it shows no
Login Name. If I then look at the same db in QA (sp_helpdb) it shows the
owner ok.
The cases where EM doesn't show a login name, seems to be the ones where the
dbo isn't mapped to a login name that has been created as a login in SQL
but is a user that's member of the SystemAdministrator role (and/or in the
local admin groups on the server). This might be obvious and clear for
others, but it confused me a little bit...;-).
Thanks for your inputs.
Regards
Steen
Wayne Snyder wrote:[vbcol=seagreen]
> dbo is always mapped to something. It is safe to map all of them to
> sa or some other login you expect will always exist... I use either
> sa or a trusted login so moving databases arouns isn't quite so much
> trouble.
>
> "Steen Persson" <SPE@.REMOVEdatea.dk> wrote in message
> news:u36YSpI$EHA.612@.TK2MSFTNGP09.phx.gbl...