SQL execution pouch while executing another program in transaction

Asked

Viewed 62 times

0

I created a program that accesses my database in transaction READ UNCOMMITED.

_oConn.BeginTransaction(IsolationLevel.ReadUncommitted, _transactionName);

Everything that runs within that transaction works normally. However, when I open SQL Server Managment Stdio and try to execute commands select, update or delete (that have already been executed in the program running in transaction) SQL Server Managment Studio is locked and only executes the command when I close the application.

Below is my database creation script.

USE [master]
GO

CREATE DATABASE [meu_banco]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'meu_banco', FILENAME = N'D:\caminho\meu_banco.mdf' , SIZE = 27200KB , MAXSIZE = UNLIMITED, FILEGROWTH = 10%)
 LOG ON 
( NAME = N'meu_banco_log', FILENAME = N'D:\caminho\meu_banco.ldf' , SIZE = 22144KB , MAXSIZE = UNLIMITED, FILEGROWTH = 10%)
GO

ALTER DATABASE [meu_banco] SET COMPATIBILITY_LEVEL = 100
GO

IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [meu_banco].[dbo].[sp_fulltext_database] @action = 'disable'
end
GO

ALTER DATABASE [meu_banco] SET ANSI_NULL_DEFAULT OFF 
GO

ALTER DATABASE [meu_banco] SET ANSI_NULLS OFF 
GO

ALTER DATABASE [meu_banco] SET ANSI_PADDING OFF 
GO

ALTER DATABASE [meu_banco] SET ANSI_WARNINGS OFF 
GO

ALTER DATABASE [meu_banco] SET ARITHABORT OFF 
GO

ALTER DATABASE [meu_banco] SET AUTO_CLOSE OFF 
GO

ALTER DATABASE [meu_banco] SET AUTO_SHRINK OFF 
GO

ALTER DATABASE [meu_banco] SET AUTO_UPDATE_STATISTICS ON 
GO

ALTER DATABASE [meu_banco] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO

ALTER DATABASE [meu_banco] SET CURSOR_DEFAULT  GLOBAL 
GO

ALTER DATABASE [meu_banco] SET CONCAT_NULL_YIELDS_NULL OFF 
GO

ALTER DATABASE [meu_banco] SET NUMERIC_ROUNDABORT OFF 
GO

ALTER DATABASE [meu_banco] SET QUOTED_IDENTIFIER OFF 
GO

ALTER DATABASE [meu_banco] SET RECURSIVE_TRIGGERS OFF 
GO

ALTER DATABASE [meu_banco] SET  DISABLE_BROKER 
GO

ALTER DATABASE [meu_banco] SET AUTO_UPDATE_STATISTICS_ASYNC ON 
GO

ALTER DATABASE [meu_banco] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO

ALTER DATABASE [meu_banco] SET TRUSTWORTHY OFF 
GO

ALTER DATABASE [meu_banco] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO

ALTER DATABASE [meu_banco] SET PARAMETERIZATION SIMPLE 
GO

ALTER DATABASE [meu_banco] SET READ_COMMITTED_SNAPSHOT ON 
GO

ALTER DATABASE [meu_banco] SET HONOR_BROKER_PRIORITY OFF 
GO

ALTER DATABASE [meu_banco] SET RECOVERY SIMPLE 
GO

ALTER DATABASE [meu_banco] SET  MULTI_USER 
GO

ALTER DATABASE [meu_banco] SET PAGE_VERIFY CHECKSUM  
GO

ALTER DATABASE [meu_banco] SET DB_CHAINING OFF 
GO

ALTER DATABASE [meu_banco] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO

ALTER DATABASE [meu_banco] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO

ALTER DATABASE [meu_banco] SET DELAYED_DURABILITY = DISABLED 
GO

USE [meu_banco]
GO

EXEC [meu_banco].sys.sp_addextendedproperty @name=N'extendpropertyA', @value=N'valorA' 
GO

EXEC [meu_banco].sys.sp_addextendedproperty @name=N'extendpropertyB', @value=N'valorB' 
GO

EXEC [meu_banco].sys.sp_addextendedproperty @name=N'extendpropertB', @value=N'valorC' 
GO

EXEC [meu_banco].sys.sp_addextendedproperty @name=N'extendpropertC', @value=N'valorD' 
GO

EXEC [meu_banco].sys.sp_addextendedproperty @name=N'extendpropertD', @value=N'valorE' 
GO

USE [master]
GO

ALTER DATABASE [meu_banco] SET  READ_WRITE 
GO


1 answer

1

It’s unclear if you’re committing or rollback on the transaction. It may be that the file is in lock and then the other system, in this case the visual studio, is not able to access. Try using the commit and closing the connection.

The classical construction is:

var transaction = _oConn.BeginTransaction(IsolationLevel.ReadUncommitted, _transactionName);

try
{

    transaction.commit();
}
catch( Exception e)
{
    transaction.roolback();
}
finally
{
  if (_oConn.State != State.Closed)
  {
      _oConn.close();
  }
  _oConn.dispose();
}
  • I am rollback. Regardless of what happens, the C# program should always perform roolback. It is one of the rules of this program. Other programs (such as SQL Server Managment studio) that access the same database are running out of transaction.

  • It will be difficult to help in a situation where "No matter what happens, the C# program should always perform roolback".. if he always has to give roolback, my friend.. I think your program should not participate in this existence. Good luck!!! kkkkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.