I am working on a large SQL Server stored procedure which is called by an integration engine, of which I have no access to the IE code (probably VB6) and I know it initiates a SQL Server transaction from this IE code (it rolls back the changes made by the stored procedure). I know SQL Server ignores the commits of inner transactions (at least that is what I have read on the MSDN site)
https://msdn.microsoft.com/en-us/library/ms189336.aspx
But does that count for transactions initiated in calling code that isn't SQL Server / T-SQL code ?
What I am trying to achieve is a database based logging system inside both Oracle and SQL Server stored proc, where the logging wont be rolled back if the update code fails. I have no control over the outer transaction and I cant partially commit the outer transaction , it has to be all or nothing for the outer transaction. I have no control of the outer. For SQL Server , I believe writing an extended stored procedure that simply writes to a table, maybe a solution that isolates itself from the outer transaction
Related
i have cloud based solutions (azure function, which reads json from service bus and convert to c# object) which inserts data into on prem sql server with multiple insert statements, are sql transactions reliable and secure over the internet.
what if connection fails during insertion in to database.
When connection fails during insertion, transaction is not complete and no rows are inserted.
When you call INSERT inside transaction, no rows are inserted until you call COMMIT TRANSACTOIN. If you use EF and transaction is not commited on end of using block, rollback is called automatically.
This is one of the typical scenario the transactions are designed for.
I have two SQL Server. I want to get data from the first one to the second and to update the first with value sent=1 there are not on the same area
What I want to do exactly is a transation in vb.net that can union all the query that will be applicated to the both db
Is it possible because if I put the query of the first db in a transaction and if i make if transaction = true then execute the second truncation (that applicated to the second db) if I lost the connection that may because problem any one can help me to join all the querys on the same transaction
In VB you would use the TransactionScope class to wrap your data access operations. It will create a local transaction to begin with and then promote it to a distributed transaction when required. The SQL Server Distributed Transaction Manager must be active for that to be possible, so that's something for you to read up on.
We're trying to use READPAST in a SQL select statement to extract data from a SQL Server 2008 database using QlikView, which is set up to use OLEDB connection to the database.
The reason for this being that we want to avoid being locked by other processes but also don't want to read any uncommitted data - otherwise we'd be using NOLOCK.
We tested the approach in SSMS initially - starting a transaction, adding a row, then separately querying the table with READPAST. This didn't return the uncommitted row as we'd want
We then added this to our OLEDB SQL query (same query, same database) in QlikView and ran the code. This time it waited for the transaction to be closed (committed or rolled back) before it finished the query.
We also tried with ODBC and SQL Native Client that are both supported by QlikView but got the same results.
We also tried with NOLOCK as the hint instead and this performs as expected - it returns the uncommitted row in both SSMS and QlikView.
Any idea why this would work in SSMS and not via OLEDB/ODBC/SQLNC?
Is there a configuration option on the database or the connection that needs changing?
Inside a transaction that have a savepoint I have to make a join with a table that is in a linked server. When I try to do it, I get the error message:
“Cannot use SAVE TRANSACTION within a distributed transaction”
The remote table data rarely changes. It is almost fixed. Is is possible to tell SqlServer to exclude this table from the transaction? I've tried a (NOLOCK) hint, but it isn't possible to use this hint for a table in a linked server.
Does anyone knows about a workaround? I'm using the ole SqlServer 2000.
One thing that you could do is to make a local copy of the remote table before you start the transaction. I know that this may sound like a lot of overhead, but remote joins are frequently a performance problem anyway and the SOP fix for that is also to make a local copy.
According to this link, the ability to use SAVEPOINTs in a Distributed transaction was dropped in SQL 7.
To allow application migration from Microsoft SQL Server 6.5 when
savepoints inside distributed transactions are in use, Microsoft SQL
Server 2000 Service Pack 1 introduces a trace flag that allows a
savepoint within a distributed transaction. The trace flag is 8599 and
can be turned on during the SQL Server startup or within an individual
session (that is, prior to enabling a distributed transaction with a
BEGIN DISTRIBUTED TRANSACTION statement) by using the DBCC TRACEON
command. When trace flag 8599 is set to ON, SQL Server allows you to
use a savepoint within a distributed transaction.
So unfortunately, you may either have to drop the bounding ACID transaction, or change the SPROC on the remote server so that it doesn't use SAVEPOINTs.
On a side note (Although I have seen that you have tagged it SQL SERVER 2000) but to make a point that SQL SERVER 2008 has remote proc trans Option for this.
In this case if the distributed table is not too large I would copy it to a temp table. If possible, include any filtering to get the number of rows to a minimum. Then you can proceed normally. Another option since the data changes rarely is copy the data to a permanant table and checking if anything has changed to prevent sending to much data over the network every time you run the transaction. You could only pull over the recent changes.
If you wish to handle transaction from UI level and you have Visual Studio 2008/.net fx 3.5 or + framework then you can wrap your logic with TransactionScope Class. If you dont have any frontends and you are working only on Sql Servers kindly ignore my answer...
Accidentally the same stored procedure was run twice at one time on our MS SQL Server 2008 R2. They were run from the same SQL Server Management Studio client and I tried to cancel them both. After 45 minutes neither process has cancelled. I read somewhere that it would help to close the query windows in SSMS so I did. However the tables the stored procedure should be writing to is still locked even though almost 20 hours has passed. I guess there is a deadlock. I hit cancel seconds after the stored procedure was initiated.
The table the stored procedure is reading from is not locked. The stored procedure is in CLR. It reads from a table, manipulate data and then use SqlBulkCopy to insert into three other tables.
The data in the tables the SP writes to can very easily be recreated. However I can neither drop nor truncate them due to the lock. I also tried KILL SPID with no result.
I have been thinking about restarting the server, but I guess it would not help because of SQL Servers data integrity.
I would really like some input on how release the lock. Several websites with lots of users depend on the database server so solutions that do not involve restarting would be much appreciated.