TransactionScope IsolationLevel not applied in Azure - sql

On our database in Azure, we have a lot of deadlocks. We tried to change the isolation level of the TransactionScope class to read committed and seriazeble, but the deadlock graphs keep saying that the isolation level is read committed (2). We assume that it keeps using the read committed snapshot isolation level, which is the default one in SQL Azure.
Is there some other setting we need to set to have SQL Azure take the isolation level we want?
Code for transactionscope:
Dim transOption As Transactions.TransactionOptions = New Transactions.TransactionOptions()
transOption.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
Using scope As New Transactions.TransactionScope(Transactions.TransactionScopeOption.Required, transOption)
...
scope.Complete
End Using
We have also tried to change Required to RequiresNew for the transaction scope option, but no success.

USE AdventureWorks2012;
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
More info:
https://social.technet.microsoft.com/wiki/contents/articles/1639.handling-transactions-in-windows-azure-sql-database.aspx

Related

Can I set the default isolation level for sql?

I can set isolation level with a transaction using sql.TxOptions. So I would like to know any way I can configure the isolation for Query, Exec.
Update: To be more precise, I am asking how to set the isolation level for connections like jdbc. The answer I have now is adding params to the database url.

Proper way to restore database transaction level from read uncommitted

I have to get data from a table which is excessively updated. Dirty read is not a problem for me. I decided to use read uncommitted in my stored procedure.
Then I added this line before select:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
I learned that this code scope is connection, unlike nolock. I heard you should change it to default after your work is done is that right?
Do I have to just add
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
end of the line? I could not find any example on the web where isolation level is changed back after work is done. Is there any example?
Only one of the isolation level options can be set at a time, and it remains set for that connection until it is explicitly changed. All read operations performed within the transaction operate under the rules for the specified isolation level unless a table hint in the FROM clause of a statement specifies different locking or versioning behavior for a table.
...
If you issue SET TRANSACTION ISOLATION LEVEL in a stored procedure or trigger, when the object returns control the isolation level is reset to the level in effect when the object was invoked. For example, if you set REPEATABLE READ in a batch, and the batch then calls a stored procedure that sets the isolation level to SERIALIZABLE, the isolation level setting reverts to REPEATABLE READ when the stored procedure returns control to the batch.
https://msdn.microsoft.com/en-us/library/ms173763.aspx

How to set transaction isolation level as read uncommitted as default for users

Is it possible to set the transaction isolation level to read uncommitted for users by default in MS SQL Server Management Studio 2012?
I was thinking it could either be done through editing a config file or changing a reg key but i haven't been able to locate anything that would change this yet.
As far as I know you can't change the default lock level.
For workloads with a lot of reads and fewer writes, you can avoid blocking queries with multiversion concurrency control. That's the default for Postgres and Oracle. In SQL Server, MVCC is called "read committed snapshot", and you can enable it with:
ALTER DATABASE YourDb SET READ_COMMITTED_SNAPSHOT ON;
You can’t. The default isolation level for all SQL Server databases is Read Committed, and your only option is to set the isolation level within a session, if you want to use a level other than the default.
You could also set SET TRANSACTION ISOLATION LEVEL within stored procedure body.
You cannot do this. As I'm sure you are aware; you should be careful when using the READ UNCOMMITTED isolation level. From MSDN:
When this option is set, it is possible to read uncommitted
modifications, which are called dirty reads. Values in the data can be
changed and rows can appear or disappear in the data set before the
end of the transaction. This option has the same effect as setting
NOLOCK on all tables in all SELECT statements in a transaction.
This means non of your results are guaranteed to contain accurate data.
You can do this in SQL Server Management Studio by setting execution options. (Tools>Options>Query Execution>SQL Server>Advanced>SET TRANSACTION ISOLATION LEVEL>)
NB: This only does it for queries executed from this instance of SSMS.

Confusion about SQL Server snapshot isolation and how to use it

I am newbie to MS Sql Server. Just a few months experience maintaining SQL Server SPs. I am reading up about transaction isolation levels for optimising an SP and am quite confused. Please help me with below questions:
If I run DBCC useroptions in ClientDB, the default value for isolation level is 'read committed'. Does this mean the DB is set to isolation level is set to READ_COMMITTED_SNAPSHOT ON ?
Is SET TRANSACTION ISOLATION LEVEL (at transaction level) same as SET READ_COMMITTED_SNAPSHOT ON (at DB level)? By this I mean that IF my DB has SNAPSHOT enabled, then can I set isolation level in my SP and process data accordingly?
is ALLOW_SNAPSHOT_ISOLATION similar to above?
I have an SP which starts off with a very long running SELECT statement that also dumps it's contents into a temp table. Then uses the temp table to UPDATE/INSERT base table. There are about 8 mil records being selected and dumped into temp table, then a similar number of total rows updated/inserted. The problem we are facing is that this SP takes up too much disk space.
It is a client DB and we do not have permissions to check disk space/log size etc in the DB. So I do not know if the tempDB/tempDB-log is taking up this disk space or clientDB/clientDB-log is. But the disk space can reduce by as much as 10GB at one go! This causes the transaction log to run out of disk space (as disk is full) and SP errors out.
If I use SNAPSHOT isolation level, will this disk space get even more affected? as it uses tempDB to versionize the data?
What I really want to do is this:
SET transaction isolation level to SNAPSHOT. Then do the SELECT into Temp table. Then BEGIN TRANSACTION and update/insert base table for say ... 1 mil records. Do this in a LOOP until all records processed. Then END TRANSACTION. Do you think this is a good idea? Should the initial SELECT be kept out of the TRANSACTION? Will this help in reducing the load on the transaction logs?
An isolation level of "read committed" isn't the same thing as setting READ_COMMITTED_SNAPSHOT ON. Setting READ_COMMITTED_SNAPSHOT ON sets the default isolation level for all queries. A query or procedure that then uses "read committed" isolation level does use snapshot isolation. See Isolation Levels in the Database Engine and SET TRANSACTION ISOLATION LEVEL in Books Online.
When the READ_COMMITTED_SNAPSHOT database option is set ON, read
committed isolation uses row versioning to provide statement-level
read consistency. Read operations require only SCH-S table level locks
and no page or row locks. When the READ_COMMITTED_SNAPSHOT database
option is set OFF, which is the default setting, read committed
isolation behaves as it did in earlier versions of SQL Server. Both
implementations meet the ANSI definition of read committed isolation.
ALLOW_SNAPSHOT_ISOLATION doesn't change the default isolation level. It lets each query or procedure use snapshot isolation if you want it to. Each query that you want to use snapshot isolation needs to SET TRANSACTION ISOLATION LEVEL SNAPSHOT. On big systems, if you want to use snapshot isolation, you probably want this rather than changing the default isolation level with READ_COMMITTED_SNAPSHOT.
A database configured to use snapshot isolation does take more disk space.
Think about moving the log files to a bigger disk.

Read Committed Snapshot

Once you alter database to use Read Commited Snapshot isolation level, OR snapshot isolation level
Do all transaction now uses that isolation as default or Read Commited is stil the default isolation level and you have to change all stored proc to use by specifying
SET TRANSACTION ISOLATION LEVEL Read_committed_snapshot to use Read Committed Snapshot
The entire database and code and transaction all use whatever your setting us
Unless you set SET TRANSACTION ISOLATION LEVEL in the code somewhere separately...