I get below errors when inserting records into database.
System.Transactions.TransactionException: The operation is not valid for the state of the transaction. ---> System.TimeoutException: Transaction Timeout --- End of inner exception stack trace --- at System.Transactions.TransactionState.EnlistPromotableSinglePhase(InternalTransaction tx, IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Transaction atomicTransaction) at System.Transactions.Transaction.EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification) at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx) at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open()
In fact, I insert data into the database using the transaction method, the code for which is described below.
TransactionOptions tOptions = new TransactionOptions(); tOptions.IsolationLevel = IsolationLevel.ReadCommitted; tOptions.Timeout = TransactionManager.MaximumTimeout; using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew, tOptions)) { }
Is there anything wrong with the above statement?
One thing worth mentioning is that I am massively embedding data in 10 tables with a large number of records and tables, and also allows you to insert duplicate records into a bulk insert, the syntax used to achieve this is mentioned below.
CREATE UNIQUE INDEX Index_a ON table1([c1], [c2]) WITH IGNORE_DUP_KEY
We would be grateful if anyone could help me in this matter.
source share