Re: Removing deadlock

From: Wayne Snyder (wayne.nospam.snyder_at_mariner-usa.com)
Date: 07/02/04


Date: Fri, 2 Jul 2004 08:22:03 -0400

There are several things you might do.
1. Select * from table(nolock)
  This allows the selector to see data which has been changed in the other
transaction (even though that trans might be rolled back..) Make sure this
makes business sense.
2. Select * from table(readpast).
      this simply excludes the locked rows from your rowset... You just do
not see any rows which are locked for insert/udpate.
3. You can bind the 2 connections together so SQL sees them as the same lock
space ( Search for bindtoken in books on line.)

-- 
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
"Viatcheslav V. Vassiliev" <msnewsgroup@www-sharp.com> wrote in message
news:OYg0dPCYEHA.4008@TK2MSFTNGP09.phx.gbl...
> Could MS SQL Server be setup to have no deadlock in this code (insert in
> transaction from one connection and select from another without closing
> transaction):
>
> //-------------------------------------------------------------
> var connStr = "Provider=SQLOLEDB;Integrated Security=SSPI;Initial
> catalog=XXX";
> var conn1 = new ActiveXObject("ADODB.Connection");
> var conn2 = new ActiveXObject("ADODB.Connection");
> conn1.Open(connStr);
> conn2.Open(connStr);
>
> var rs = new ActiveXObject("ADODB.Recordset");
> var cmd = new ActiveXObject("ADODB.Command");
>
> conn1.BeginTrans();
> cmd.ActiveConnection = conn1;
> WScript.Echo("Inserting");
> cmd.CommandText = "INSERT INTO Table1 VALUES('Example')";
> cmd.Execute();
> cmd = null;
>
> WScript.Echo("Selecting");
> //Deadlock is here
> rs.Open("SELECT * FROM Table1", conn2);
>
> rs.Close();
> rs = null;
>
> conn1.RollbackTrans();
>
> conn1.Close();
> conn1 = null;
>
> conn2.Close();
> conn2 = null;
>
> WScript.Echo("Done");
> //---------------------------------------------------------------
>
> Best regards,
> Viatcheslav V. Vassiliev
>
>


Relevant Pages

  • Removing deadlock
    ... transaction from one connection and select from another without closing ... var conn1 = new ActiveXObject; ... var conn2 = new ActiveXObject; ...
    (microsoft.public.sqlserver.programming)
  • Re: Removing deadlock
    ... Wayne Snyder, MCDBA, SQL Server MVP ... > Could MS SQL Server be setup to have no deadlock in this code (insert in ... > var conn1 = new ActiveXObject; ...
    (microsoft.public.sqlserver.programming)
  • Re: Transaction Isolation Level
    ... This means that while I initiate a transaction selecting all new orders it ... My query is executed on a SQL server 2005. ... the isolation level you should use is snapshot isolation. ...
    (comp.databases.ms-sqlserver)
  • Re: Windows Completely Locks Up!! FREEZE
    ... failing to start/run the Distributed Transaction Coordinator. ... Error Specifics: ... The Business Contact Manager SQL Server Startup Service service terminated ... The service did not respond to the start or control request in a timely ...
    (microsoft.public.windowsxp.general)
  • Re: Asynchronous Stored Procedure Never Returns - Help?
    ... If you have the Sql Server 2000 or 2005 docs they are thorough and can be ... for Transaction SQL Reference from the drop-down or select a keyword from ... your query in Query Analyzer or Sql Server Management Studio, ...
    (microsoft.public.dotnet.languages.csharp)