Transaction Locking Tables

Apr 16, 2004

Hi all,
I am writing an sp which includes insert and update statements.
sp is working fine.
But when I tried to make it as a single Transaction its not working(waiting indefinetly at second insert statement).tables are getting locked.
what could be the possible reason for tables getting locked indefinetly.
I Tried with
set transaction isolationlevel serializable
option.
There are several insert into statements.some of them on the same tables again and again.
any help would be greatly appreciated.
Thanks.

View 3 Replies


ADVERTISEMENT

Transaction Locking

Jun 7, 2006

I'm using Sql Server 2005...
I'm creating a transaction and enlisting the commands inside vb.net code as well as surrounding the t-sql in an "Begin Trans --- Commit Trans" block. I also have the Isolation level set to the highest (Serializable) in the vb.net code and the sprocs.
I'm running 4 instances of the app on 1 server and 4 instances of the app on another server. I am handling the lockouts just fine and writing them to an error table within the db. The app keeps spinning and producing data just fine.
There are 3 places where the locking may occur within the app. Two of them are just fine (which is a select and and insert). The app will eventually cycle around and pick up the records taht may have been locked out. My concern is the Update portion which updates stats based off the Insert done previously. If the records never get updated, the only way I would know if they were processed would be to check in our Error table to see if the record exists.
I would like to know if there is any way possible to cut down on the number of lockouts (which may be perfectly normal) and to get a way to update that table I just talked about. Should I be using different isolation levels, etc. --- anything of importance might be useful.
 

View 1 Replies View Related

Transaction Locking

Oct 3, 2000

I have a stored-procedure which insert's records. In it I have a Begin Tran so if it fails I can run a rollback. When I'm inserting big number of records it creates X locks and it start's blocking other users.

View 3 Replies View Related

Transaction Locking

Oct 24, 2007

Hi,

How can I know when a table is lock by a transaction?

I have found about the procedure sp_lock but it doesn€™t show me the table that the transaction is locking and when I execute an update statement through an application the application crashed waiting for the transaction to finish.

Any help will be appreciated.

View 3 Replies View Related

Transaction Locking

Jun 8, 2006

I'm using Sql Server 2005...

I'm creating a transaction and enlisting the commands inside vb.net code as well as surrounding the t-sql in an "Begin Trans --- Commit Trans" block. I also have the Isolation level set to the highest (Serializable) in the vb.net code and the sprocs.

I'm running 4 instances of the app on 1 server and 4 instances of the app on another server. I am handling the lockouts just fine and writing them to an error table within the db. The app keeps spinning and producing data just fine.

There are 3 places where the locking may occur within the app. Two of them are just fine (which is a select and and insert). The app will eventually cycle around and pick up the records taht may have been locked out. My concern is the Update portion which updates stats based off the Insert done previously. If the records never get updated, the only way I would know if they were processed would be to check in our Error table to see if the record exists.

I would like to know if there is any way possible to cut down on the number of lockouts (which may be perfectly normal) and to get a way to update that table I just talked about. Should I be using different isolation levels, etc. --- anything of importance might be useful.

View 1 Replies View Related

Transaction Locking Issue

Jun 6, 2001

I have SQL server 7 machine here but this problem will occure with any
version I suppose.
We have a web application and NT server and client machines.

I have a stored procedure which has

Begin transaction
statement1
statement2 and so on... these could be any DML statements or another
proecdure call.

commit transaction
end

We cannot commit this transaction untill the process is complete, I mean it
processes all statements.

Now the problem is when one of the statement takes a ong time the page will
time out.. keeping that transaction open.

In the mean time other users are doing their changes in the database.. this
goes on for a while and nobody noticed it.

When the connection to the application was broken for some reason. The
transaction which was open was cancelled ... and everthing rollsback from
the time the 1st transaction failed ( timed out) so there is nothing in the
database that other users did..

How do you solve this problem ?

View 1 Replies View Related

Transaction/Locking Question

Nov 26, 2004

Hi,
Very new to locking/transactions, so any help appreciated with the following:

I want to create a stored procedure with statements that read an Integer value in a single row table, return this as output from the procedure to my web form, and increment it incremented by 1 (for the next call of the procedure).

I need to be absolutely sure that while the value is being read and updated, another call to the procedure cannot read/update this value until the current is call completed, i.e some sort of locking on the value.

Question - If I wrap my SELECT and UPDATE statements in a BEGIN TRAN and COMMIT TRAN, will this be enough? e.g Is this sufficient:

CREATE PROCEDURE sp_test
@retval int output
AS

BEGIN TRAN

SELECT @retval = POID FROM OMS_SYSDATA
UPDATE OMS_SYSDATA SET POID=POID+1

COMMIT TRAN
GO

Or do I need to start using things like HOLDLOCK/UPDLOCK within statements?

Cheers
Greg

View 6 Replies View Related

Locking A Table For The Duration Of A Transaction.

Feb 20, 2004

We have a nightly script that drops and rebuilds a table. Problem is before the script has had a chance to complete the building of the primary key, it fails due to some other process gaining access to the table.

My question is this: how do I lock a table for the duration of the transaction.

Here is what I think would work:

SET ISOLATION LEVEL SERIALIZABLE

BEGIN TRANSACTION

DROP TABLE <table>...
CREATE TABLE <table>...

INSERT INTO <table> WITH (TABLOCKX) ...

ALTER TABLE <table> ADD CONSTRAINT PRIMARY KEY ...

COMMIT

Any insight as to whether or not I am correct, or if I am not, what would be the correct way.

View 9 Replies View Related

Locking Tables

Aug 16, 2001

I have a Table TEST (TCD int,NUMCD int ,TNM varchar(20))
where TCD is an identity column
1- When inserting I want the value of TCD to be inserted also in NUMCD.
2- I want to prevent two users to insert the same value of NUMCD
if executing the same insert at the same time .
For this i use the following insert :

INSERT Into TEST WITH (TABLOCK)
(NUMCD,TNM) select IsNull(Max(TCD),0)+1,'Abcd' from TEST
- Is the sql statment above resolve my probleme. If not is there someone who can help me resolving this probleme.

Think you for helping me

View 1 Replies View Related

Help Req With Locking Tables...

Mar 8, 2005

Hi DB Gurus..

I need to lock one table ( table-level locking) as i dont want anyone to modify till i finish my stored procedure.

I need simple example on how to Lock the table and unlock..

Something like this

Lock Table Name...
...

statements go here
...

Unlock table...

Is this possible in Sql server 2000

waiting for ur replies..

Thanks in Advance

View 3 Replies View Related

Locking Tables

May 2, 2008

I've written a C# program which (1) Calls a SQL stored procedure which, among other things, updates a table with email information and then (2) sends the email via Outlook. This is ultimately going to be on a production server where the C# email program can be called by a number of processes.

If more than one instance of the email program is invoked at the same time, problems could occur. For instance, after the first instance updated the table it would then begin the process of creating and sending the email, but if a second instance is called at that time,it could be updating the SQL table which I think would screw up the email the first instance was creating. As a solution, I've been looking into locking tables. What I'd like to do is lock the table after it's been updated and unlock it after the email is sent. I know I can use the SLEEP function in C# so if it tries to access the table and it's locked, to wait 20 seconds or so and try again.

So how can you lock (and unlock?) a table in SQL? I'm reading about using WITH (TABLOCK) in the UPDATE query, but I'm not sure that will solve my problem. From what I can tell, TABLOCK automatically "unlocks" when the update is done. That still wouldn't resolve the issue of instance 2 updating the SQL table after instance 1 had updated it, but BEFORE instance 1 has completing creating the email (based off the data in the table).

Thanks

View 3 Replies View Related

Locking Tables...

Apr 18, 2006

Hi,

I have a question regarding locking tables in transact sql.

The situation is the following:
a table named TableA which has two columns; ID and Name.
a table named IDTable which has two columns REF_ID, REF_PREFIX

in the IDTable we have the following entry:
REF_ID = 1, REF_PREFIX = 'TbA'

I have a stored procedure that will make a lot of inserts into the TableA. However there is another program that makes insert into TableA as well.

They both read from the IDTable to get which ID to use (ID of course needs to be unique).

A simplified version of the stored procedure is:
"SELECT all entries to move from another table"
"While not all entries moved"
"Get id from IDTable"
"Insert into TableA"
"Update IDTable"
"Loop"

I would like to have it like:
"SELECT all entries to move from another table"
"While not all entries moved"
"lock IDTable and TableA"
"Get id from IDTable"
"Insert into TableA"
"Update IDTable"
"unlock IDTable and TableA"
"Loop"

and thus giving the other program a change to "get in line" to use the tables but not using them at the same time.

So my questions:
1) Is this possible (if not, please explain why)?
2) How do I lock a table, I have tried "LOCK TABLE" but that just gives me syntax error?


Thank you in advance.

BR Mikael

View 1 Replies View Related

Tempdb - Locking System Tables

Mar 9, 1999

I have some stored procs that have temp table creations in them using "create table #tmptable...". I have noticed that when running the procs, sp_lock shows tempdb system tables being locked. I totally expect this. But, put a PowerBuilder front end on, and I get another situation. Calling the stored procs from PowerBuilder causes the same locks to occur, but they are not released after the data is displayed through the application. Furthermore, this blocks other users from creating anything in tempdb until the user logs off of the application and ends the connection to the database.

please help - is there something I am missing in my procedures, or is this a PowerBuilder issue?

Thanks!

Dean

View 1 Replies View Related

Nomore Snapshot Without Locking Tables?

Oct 3, 2006

HI There

After upgrading my publishers to 2005 i noticed that i cannot specify not to lock tables during snapshot during publication creation, also not on publication properties, and i see sp_addpublication has no such parameter, is there no longer an option not to lock publication tables during snapshot?

Thanx

View 3 Replies View Related

Select Into And Locking System Tables -- Am I In Trouble?

Sep 27, 2000

I am doing a ‘Select into’ to make a table from at another table which has as many as 130 millions rows (its well indexed). The new table will most often have about 1000 rows. (During the running of the app, the app will be making many new tables, since hopefully this will be a ‘popular’ item by the users. After the users ‘use’ them, they are dropped.)

I know that locks are held on various system tables (including sysobjects) during this ‘select into’ process. Are they held for the entire process?

What should I be concerned about doing ‘select into’?

Thanks for any help,

Judith

View 2 Replies View Related

PROBLEM: Tables Are Locking Up When Attempting To Save Data

Jul 14, 2003

Over the weekend, one of our out-of-house programmers ran an update to our three main tables. I know these are kind of broadstrokes, but basically he compared the data and updated certain fields when it met certain conditions (lots of rules basically). The three tables are one-to-one and contain a little over a million records. The comparison file contained around 400k records.

The scripts made it through 250k records from the comparison file before he had to stop it for the weekend.

When I came in to test the data yesterday - I was met with problems on my front end application - it would lock up on the write back to the database. I went into EP and experienced the same thing after making any changes to a record, it would just lock up. This only appears to be a problem on the 2 bigger tables of the 3. I currently have 12 gigs or so free on that box and I have already shrunk the log and data files.

I tried removing and re-adding the indexes, but I am freezing up everytime I try to either change or delete the Clustered Index on the Primary Key. I don't know why, but I thought maybe that was my issue.

I know this is pretty broad, but even if someone could give me ideas as to why SQL would lock up like that when trying to just save the data, it would be most helpful.

NOTE: There were NO structure changes in the update process and my restored data from Friday works perfect.

If you need more info, just ask. Thanks in advance for the help.

Don
elitecobra2000@yahoo.com

View 14 Replies View Related

Linked Server Error... Openquery() Locking Tables

Feb 1, 2008



Hi All -

My Set up:

Server A - Oracle 10g Database
Server B - SQL2005
Client PC - Sql Express

Server A holds all data. I am using a linked server to connect server A and B. I use a set of stored procedures containing the openquery() syntax to get data from Server A to Server B. These stored procedures run every 20 minutes. I then create a publisher on Server B. I subscribe from the client PC to publisher to get data down from Server B to client(Download only subscription).

When I fire up the stored procedures and attempt to replicate, everything works fine. It appears after about 4-5 hours of the stored procedures running replication begins to hang more and and more until eventually it hangs for about 10 minutes and I recieve the following error:

Command attempted:
{call sp_MSreleasemakegenerationapplock}
Error messages:
The merge process was unable to create a new generation at the 'Publisher'. Troubleshoot by restarting the synchronization with verbose history logging and specify an output file to which to write. (Source: MSSQL_REPL, Error number: MSSQL_REPL-2147200994)

I'm not sure if there is an error with openquery() locking? There is some locking activity going on with the TempDB and and Server B database. I've also come across some threads talking about the agent profiles. I'm very new to replication and very confused by all of the options in the agent profiles. Any help would be greatly appreciated!

View 1 Replies View Related

Concurrent Snapshot Still Locking Tables For A Long Time

Apr 5, 2006

We have transactional replication running with a seperate publisher/distributor/subscriber. I want to add a couple of articles to the publication, and then initialise them. I have added the articles and run sp_refreshsubscriptions

I now want to refresh the subscriptions. I have selected not to lock the tables on the snaphot tab of the publication properties, but whenever I run the snapshot agent it locks the application solid! Its odd, as soon as I run the snaphot agent, the phones start ringing within minutes. The application is Great Plains and I have set the snapshot agent to run nightly anyway.

Is there any way I can run the snapshot agent during working hours to refresh this one article? Once I have successfully done this, I have a number of articles want to add - but I can't lock the tables when refreshing the initial snaphot.

View 1 Replies View Related

Remote Tables Are Not Updatable. Updatable Keyset-driven Cursors On Remote Tables Require A Transaction With The REPEATABLE_READ

May 16, 2008



Has anyone seen this error? It comes up when my app executes a select statement via linked server (from MSSQL 2000 to 2005) the second time it runs. It's basically a timed poll of tables in the remote database. It works once but the second time it executes I get the error from the remote db, it's just a select but I guess the cursor is still open so it can't run again. After the exception the select will run again, once and it just repeats. I have researched it a little and it looks like it mostly has to do with the isolation level of the transaction. Unfortunately based on the componet being used to access the database I don't beleive I have the ability to use transact SQL to call the isolation level (s) listed.

Here's the weird part though, at another site the same scenario is running fine. Same primary and remote db versions of MSSQL as well as the application and it runs fine. I guess my question is what type of setup parameters that may be defined in MSSQL 2005 for the remote database might make it behave in this manner in one instance and not the other? TIA in advance for any thoughts/assistance.

DT

View 1 Replies View Related

Get Master And Transaction Tables List

Apr 16, 2008

Pls Tell

Me How to get Name of Master and Transaction Table From The DataBase




Yaman

View 3 Replies View Related

Inserting Into Two Tables And Transaction Problem

Jun 30, 2006

CREATE PROCEDURE SimpleInsert (@custname custname_type,@carname carname_type)ASBEGIN TRANSACTIONINSERT Customers (CustName) VALUES (@custname)IF @@error <> 0 BEGIN ROLLBACK TRANSACTION RETURN 1 ENDDECLARE @custid intSELECT @custid = scope_identity()INSERT Cars (ID, CarName) VALUES (@custid, @carname)IF @@error <> 0 BEGIN ROLLBACK TRANSACTION RETURN 1 ENDCOMMIT TRANSACTIONIF no error this works but to test transaction, I chanded the tablename of second insert to 'car' in which doesn't exist and this erroroccured (calling sp by ASP .NET page):Invalid object name 'car'. Transaction count after EXECUTE indicatesthat a COMMIT or ROLLBACK TRANSACTION statement is missing. Previouscount = 0, current count = 1.ThanksHabib

View 2 Replies View Related

Inserting Data Into Multiple Tables In 1 Transaction

Feb 7, 2007

Hello everyone, My web application uses SQL Server database and I am connecting via standard SqlConnection object and running stored procedures using SqlCommand object. In one of my page, I have data coming from 2 different tables. Now , data from 1 table comes as only single record. But from other table it comes as multiple records. Meaning, data that I read as 1 record, goes to different textbox and dropdown controls on page. Data that comes in multiple rows, I am binding that data with DataGrid. Now, in aspx page data from both table can be updated and on aspx page I only need to provide a single save button. Now, I am not sure how to save/insert/update a single row in 1 table and multiple rows in another table in 1 transaction. I thought of stored procedure. But I don't think its straightforward with stored procedures since table with multiple records, I am not sure how to pass all the records in stored procedure's arguments.Is there any way that I can control whole transaction in ASP .NET? Thanks,Ujjaval       

View 5 Replies View Related

INSERTING MULTIPLE RELATED TABLES IN A TRANSACTION

Jun 2, 2005

I have a problem there must be an answer to, but I cannot find it anywhere on Google.I have a SQL INSERT statement in an ASP.Net page that  inserts into 3 tables in one transaction.The problem is that 2 of the 3 tables are children of the main table, and I need to get the Parent table's Primary Key [which of course has not been inserted yet] to insert into the Child tables.How do I do this?THanks.Doug

View 1 Replies View Related

Does SQL Server Put A Shared Lock On All Tables Within A Transaction?

Feb 17, 2006

Would table1, table2 and table3 in code below, be locked with a shared lock from start of transaction to the end of transaction Or they would only be locked for the duration of  their update, or insert statements and not for the entire transaction? Default isolation level is in effect in SQL Server.
 begin tran   update table1 set column1 = 100   if @ERROR = 0     begin       declare @stat int       set @stat = (select stat from table2 where  employeeid = 10)      insert into table3 (col1, col2) values (@stat , 325)      if @@ERROR = 0          commit tran      else         rollback tran     end   else      roll back tran

View 2 Replies View Related

Do Tables Using A Different Filegroup Log Trans To The Same Transaction Log Used By Primary?

Sep 26, 2007

we like some of the advantages filegroups offer but wonder if the purpose is somewhat defeated if it is true that tables sitting on other filegroups still have to work with the same transaction log that the db's primary tables work with.

View 4 Replies View Related

Using Transaction While Inserting To Master And Child Tables

May 26, 2008

Hi All,

In my DataFlow i have OleDBDataSource and OleDB Command. Using these i am inserting data to master and child tables.

In OleDBDataSource , i am inserting into master table and returning the ID of newly inserted rows. Next in the OleDB Command, i am inserting to child table using the ID returned from OleDBDataSource.

It is working fine. Now i want to put this in the Transaction so that if it fails to insert into child table, the changes made to the master table should be rolled back. I tried by giving Transaction Supported for dataflow. But does not looks like it works for me. Please suggest me the best approach for this.

Thanks in advance
DV

View 2 Replies View Related

Error 8525: Distributed Transaction Completed. Either Enlist This Session In A New Transaction Or The NULL Transaction.

May 31, 2008

Hi All

I'm getting this when executing the code below. Going from W2K/SQL2k SP4 to XP/SQL2k SP4 over a dial-up link.

If I take away the begin tran and commit it works, but of course, if one statement fails I want a rollback. I'm executing this from a Delphi app, but I get the same from Qry Analyser.

I've tried both with and without the Set XACT . . ., and also tried with Set Implicit_Transactions off.

set XACT_ABORT ON
Begin distributed Tran
update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.TRANSACTIONMAIN
set REPFLAG = 0 where REPFLAG = 1
update TSADMIN.TRANSACTIONMAIN
set REPFLAG = 0 where REPFLAG = 1 and DONE = 1
update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.WBENTRY
set REPFLAG = 0 where REPFLAG = 1
update TSADMIN.WBENTRY
set REPFLAG = 0 where REPFLAG = 1
update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.FIXED
set REPFLAG = 0 where REPFLAG = 1
update TSADMIN.FIXED
set REPFLAG = 0 where REPFLAG = 1
update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.ALTCHARGE
set REPFLAG = 0 where REPFLAG = 1
update TSADMIN.ALTCHARGE
set REPFLAG = 0 where REPFLAG = 1
update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.TSAUDIT
set REPFLAG = 0 where REPFLAG = 1
update TSADMIN.TSAUDIT
set REPFLAG = 0 where REPFLAG = 1
COMMIT TRAN


It's got me stumped, so any ideas gratefully received.Thx

View 1 Replies View Related

SSIS, Distributed Transaction Completed. Either Enlist This Session In A New Transaction Or The NULL Transaction.

Feb 22, 2007

I have a design a SSIS Package for ETL Process. In my package i have to read the data from the tables and then insert into the another table of same structure.

for reading the data i have write the Dynamic TSQL based on some condition and based on that it is using 25 different function to populate the data into different 25 column. Tsql returning correct data and is working fine in Enterprise manager. But in my SSIS package it show me time out ERROR.

I have increase and decrease the time to catch the error but it is still there i have tried to set 0 for commandout Properties.

if i'm using the 0 for commandtime out then i'm getting the Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.

and

Failed to open a fastload rowset for "[dbo].[P@@#$%$%%%]". Check that the object exists in the database.

Please help me it's very urgent.

View 3 Replies View Related

How To Manage Stored Procedure Transaction Involving Update In Several Tables

Jul 22, 2004

I am running a vba procedure ( adp file ) that executes successively 5 stored procedures . however it happens that the execution breaks at the middle of the code thus giving a situation where only 2 tables among 5 are updated.

Is it any solution to rollback transactions update already done before
the code breaks due to error ?

I was thinking about combining all stored proc on a big one and use
Begin transaction - commit transaction and rollback transaction ... however i am not sure wheter updates involving several tables can be handled on one transaction.

Any advise highly appreciated !

View 2 Replies View Related

Referential Integrity - Linking Multiple Tables To Transaction Table

Mar 3, 2006

I have transaction table where the rows entered into the transactioncan come a result of changes that take place if four different tables.So the situation is as follows:Transaction Table-TranId-Calc AmountTable 1 (the amount is inserted into the transaction table)- Tb1Id- Tb1AmtTable 2 (an amount is calculated based on the percentage and insertedinto the transaction table)-Tbl2Id-Tb2PercentageTable 3 (the amount is inserted into the transaction table)-Tbl3Id-Tbl3AmutTable 4 (an amount is calculated based on the percentage and insertedinto the transaction table. )-Tbl2Id-Tb2PercentageHow do I create referential integrity between the Transaction table andthe rest of the tables. When I make changes to the values in Table 1 -4, I need to be able to reflect this in the Transaction table.Thanks.

View 6 Replies View Related

Distributed Transaction Completed. Either Enlist This Session In A New Transaction Or The NULL Transaction.

Feb 6, 2007

I am getting this error  :Distributed transaction completed. Either enlist this session in a new
transaction or the NULL transaction. Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code. Exception Details:
System.Data.OleDb.OleDbException: Distributed transaction completed. Either
enlist this session in a new transaction or the NULL transaction.have anybody idea?!

View 1 Replies View Related

Distributed Transaction Completed. Either Enlist This Session In A New Transaction Or The NULL Transaction.

Dec 22, 2006

i have a sequence container in my my sequence container i have a script task for drop the existing tables. This seq. container connected to another seq. container. all these are in for each loop container when i run the package it's work fine for 1st looop but it gives me error for second execution.

Message is like this:

Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.

View 8 Replies View Related

Distributed Transaction Completed. Either Enlist This Session In A New Transaction Or The NULL Transaction. (HELP)

Jan 8, 2008

Hi,

i am getting this error "Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.".

my transations have been done using LINKED SERVER. when i manually call the store procedure from Server 1 it works but when i call it through Service broker it dosen't work and gives me this error.



Thanks in advance.


View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved