Showing posts with label transaction. Show all posts
Showing posts with label transaction. Show all posts

Monday, March 19, 2012

Error create a second independent transaction inside a CLR stored procedure?

I use the context connection for the "normal" work in the CLR procedure.
But I need to commit some data in every case. So I need to create a second transaction which is independent from the calling transaction.

What is the best way to do this inside a CLR procedure?

Thanx a lot

Hi!

Create another connection to the server and create a transaction on this second connection. Please note that since your main connection is inproc (“context connection=true” in the connection string), the second connection should be non-inproc (network. Of cause, you can connect to the same server.).

|||Thank you,

I tried this already. But I got an error when I call BeginTransaction on the second connection. When I remember correctly it as "Transcation already in use by another session". I call the procedure from t-sql inside a begin tran block

Any idea about that?

I will try to build a small example an post it here.|||

Hello,
I made a small example to reproduce the error.

CLR procedure
<Microsoft.SqlServer.Server.SqlProcedure()> _

Public Shared Sub Test(ByVal sConnectString As String)

Dim t As SqlClient.SqlTransaction = Nothing

Dim c As SqlClient.SqlConnection = Nothing

c = New SqlClient.SqlConnection(sConnectString)

c.Open()

t = c.BeginTransaction()

t.Commit()

c.Close()

End Sub

T-SQL caller:
begin tran
execute Test 'Server=(local);database=cpwerx;user Id=sa;password=xyz'
commit tran

Error:
A .NET Framework error occurred during execution of user defined routine or aggregate 'Cas':
System.Data.SqlClient.SqlException: Transaction context in use by another session.
System.Data.SqlClient.SqlException:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.PropagateTransactionCookie(Byte[] cookie)
at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)
at System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction)
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()

|||

Hi!

Modify your connection string so that it has "Enlist=false" in it. Otherwise the connection inherits current transaction.

More on "Enlist" option is in doc on SqlConnection.ConnectionString property

|||

Than you!

We've been stuck for a week. We had a .Net CLR stored procedure that worked locally but, failed when invoked remotely. That connection string setting is exactly what we needed.

-Joe

Sunday, February 19, 2012

Error backing up Transaction Logs

This is the error I get for the database named, "NoteServe4005". I get this error for all databases whether I attempt to backup manually or automatically.
[4] Database NoteServe4005: Transaction Log Backup...
Destination: [c:\backup\NoteServe4005\NoteServe4005_tlog_200405 041500.TRN]
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 3241: [Microsoft][ODBC SQL Server Driver][SQL Server]The media family on device 'c:\backup\NoteServe4005\NoteServe4005_tlog_200405 041500.TRN' is incorrectly formed. SQL Server cannot process this media fami
ly.
[Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP LOG is terminating abnormally.
I searched support for the error pulling up only KB:297104 which says that this can happen when transaction log files exceed 4GB. However, the T-Log in this example is only 50MB. It also says the error is fixed by SP1 and I have SP3a. There's also a worka
round which involves setting the trace flag to 3111, but that didn't seem to make a difference either.
Ideas?
What is the actual backup command your using?
Andrew J. Kelly SQL MVP
"Garrett Taylor" <gtaylor@.westerntitle.net> wrote in message
news:1049DD05-2DBF-499D-AE0F-C263FAB62C90@.microsoft.com...
> This is the error I get for the database named, "NoteServe4005". I get
this error for all databases whether I attempt to backup manually or
automatically.
> [4] Database NoteServe4005: Transaction Log Backup...
> Destination:
[c:\backup\NoteServe4005\NoteServe4005_tlog_200405 041500.TRN]
> [Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 3241: [Microsoft][ODBC
SQL Server Driver][SQL Server]The media family on device
'c:\backup\NoteServe4005\NoteServe4005_tlog_200405 041500.TRN' is incorrectly
formed. SQL Server cannot process this media family.
> [Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP LOG is terminating
abnormally.
> I searched support for the error pulling up only KB:297104 which says that
this can happen when transaction log files exceed 4GB. However, the T-Log in
this example is only 50MB. It also says the error is fixed by SP1 and I have
SP3a. There's also a workaround which involves setting the trace flag to
3111, but that didn't seem to make a difference either.
> Ideas?
|||I'm running it from Enterprise Manager both as a scheduled
job and manually.

>--Original Message--
>What is the actual backup command your using?
>--
>Andrew J. Kelly SQL MVP
>
>"Garrett Taylor" <gtaylor@.westerntitle.net> wrote in
message[vbcol=seagreen]
>news:1049DD05-2DBF-499D-AE0F-C263FAB62C90@.microsoft.com...
named, "NoteServe4005". I get
>this error for all databases whether I attempt to backup
manually or
>automatically.
>[c:\backup\NoteServe4005
\NoteServe4005_tlog_200405041500.TRN][vbcol=seagreen]
[Microsoft][ODBC
>SQL Server Driver][SQL Server]The media family on device
>'c:\backup\NoteServe4005
\NoteServe4005_tlog_200405041500.TRN' is incorrectly[vbcol=seagreen]
>formed. SQL Server cannot process this media family.
LOG is terminating[vbcol=seagreen]
>abnormally.
KB:297104 which says that
>this can happen when transaction log files exceed 4GB.
However, the T-Log in
>this example is only 50MB. It also says the error is
fixed by SP1 and I have
>SP3a. There's also a workaround which involves setting
the trace flag to
>3111, but that didn't seem to make a difference either.
>
>.
>
|||You might want to give MS PSS a call.
http://support.microsoft.com/default...d=fh;EN-US;sql SQL Support
http://www.mssqlserver.com/faq/general-pss.asp MS PSS
Andrew J. Kelly SQL MVP
"Garrett Taylor" <gtaylor@.westerntitle.net> wrote in message
news:95f101c43380$92fb9c10$a301280a@.phx.gbl...[vbcol=seagreen]
> I'm running it from Enterprise Manager both as a scheduled
> job and manually.
> message
> named, "NoteServe4005". I get
> manually or
> \NoteServe4005_tlog_200405041500.TRN]
> [Microsoft][ODBC
> \NoteServe4005_tlog_200405041500.TRN' is incorrectly
> LOG is terminating
> KB:297104 which says that
> However, the T-Log in
> fixed by SP1 and I have
> the trace flag to

Error backing up Transaction Logs

This is the error I get for the database named, "NoteServe4005". I get this error for all databases whether I attempt to backup manually or automatically.
[4] Database NoteServe4005: Transaction Log Backup..
Destination: [c:\backup\NoteServe4005\NoteServe4005_tlog_200405041500.TRN
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 3241: [Microsoft][ODBC SQL Server Driver][SQL Server]The media family on device 'c:\backup\NoteServe4005\NoteServe4005_tlog_200405041500.TRN' is incorrectly formed. SQL Server cannot process this media family
[Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP LOG is terminating abnormally
I searched support for the error pulling up only KB:297104 which says that this can happen when transaction log files exceed 4GB. However, the T-Log in this example is only 50MB. It also says the error is fixed by SP1 and I have SP3a. There's also a workaround which involves setting the trace flag to 3111, but that didn't seem to make a difference either
IdeasIf this file "c:\backup\NoteServe4005\NoteServe4005_tlog_200405041500.TRN" exists, delete it.Make sure that you also have sufficient disk space to store the new backup(s). HTH
-- Garrett Taylor wrote: --
This is the error I get for the database named, "NoteServe4005". I get this error for all databases whether I attempt to backup manually or automatically.
[4] Database NoteServe4005: Transaction Log Backup..
Destination: [c:\backup\NoteServe4005\NoteServe4005_tlog_200405041500.TRN
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 3241: [Microsoft][ODBC SQL Server Driver][SQL Server]The media family on device 'c:\backup\NoteServe4005\NoteServe4005_tlog_200405041500.TRN' is incorrectly formed. SQL Server cannot process this media family
[Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP LOG is terminating abnormally
I searched support for the error pulling up only KB:297104 which says that this can happen when transaction log files exceed 4GB. However, the T-Log in this example is only 50MB. It also says the error is fixed by SP1 and I have SP3a. There's also a workaround which involves setting the trace flag to 3111, but that didn't seem to make a difference either
Ideas|||The file doesn't already exist and I have more than 50GB
free where my transaction file is only 50MB.
>--Original Message--
>If this file "c:\backup\NoteServe4005
\NoteServe4005_tlog_200405041500.TRN" exists, delete
it.Make sure that you also have sufficient disk space to
store the new backup(s). HTH.
> -- Garrett Taylor wrote: --
> This is the error I get for the database
named, "NoteServe4005". I get this error for all databases
whether I attempt to backup manually or automatically.
> [4] Database NoteServe4005: Transaction Log Backup...
> Destination: [c:\backup\NoteServe4005
\NoteServe4005_tlog_200405041500.TRN]
> [Microsoft SQL-DMO (ODBC SQLState: 42000)] Error
3241: [Microsoft][ODBC SQL Server Driver][SQL Server]The
media family on device 'c:\backup\NoteServe4005
\NoteServe4005_tlog_200405041500.TRN' is incorrectly
formed. SQL Server cannot process this media family.
> [Microsoft][ODBC SQL Server Driver][SQL Server]
BACKUP LOG is terminating abnormally.
> I searched support for the error pulling up only
KB:297104 which says that this can happen when transaction
log files exceed 4GB. However, the T-Log in this example
is only 50MB. It also says the error is fixed by SP1 and I
have SP3a. There's also a workaround which involves
setting the trace flag to 3111, but that didn't seem to
make a difference either.
> Ideas?
>.
>

Error backing up Transaction Logs

This is the error I get for the database named, "NoteServe4005". I get this
error for all databases whether I attempt to backup manually or automaticall
y.
[4] Database NoteServe4005: Transaction Log Backup...
Destination: & #91;c:\backup\NoteServe4005\NoteServe400
5_tlog_200405041500.TR
N]
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 3241: [Microsoft]&#
91;ODBC SQL Server Driver][SQL Server]The media family on device 'c:\bac
kup\NoteServe4005\NoteServe4005_tlog_200
405041500.TRN' is incorrectly formed
. SQL Server cannot process this media fami
ly.
[Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP LOG is ter
minating abnormally.
I searched support for the error pulling up only KB:297104 which says that t
his can happen when transaction log files exceed 4GB. However, the T-Log in
this example is only 50MB. It also says the error is fixed by SP1 and I have
SP3a. There's also a worka
round which involves setting the trace flag to 3111, but that didn't seem to
make a difference either.
Ideas?If this file " c:\backup\NoteServe4005\NoteServe4005_tl
og_200405041500.TRN" e
xists, delete it.Make sure that you also have sufficient disk space to store
the new backup(s). HTH.
-- Garrett Taylor wrote: --
This is the error I get for the database named, "NoteServe4005". I get this
error for all databases whether I attempt to backup manually or automaticall
y.
[4] Database NoteServe4005: Transaction Log Backup...
Destination: & #91;c:\backup\NoteServe4005\NoteServe400
5_tlog_200405041500.TR
N]
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 3241: [Microsoft]&#
91;ODBC SQL Server Driver][SQL Server]The media family on device 'c:\bac
kup\NoteServe4005\NoteServe4005_tlog_200
405041500.TRN' is incorrectly formed
. SQL Server cannot process this media
family.
[Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP LOG is ter
minating abnormally.
I searched support for the error pulling up only KB:297104 which says that t
his can happen when transaction log files exceed 4GB. However, the T-Log in
this example is only 50MB. It also says the error is fixed by SP1 and I have
SP3a. There's also a
workaround which involves setting the trace flag to 3111, but that didn't se
em to make a difference either.
Ideas?|||The file doesn't already exist and I have more than 50GB
free where my transaction file is only 50MB.

>--Original Message--
>If this file "c:\backup\NoteServe4005
\NoteServe4005_tlog_200405041500.TRN" exists, delete
it.Make sure that you also have sufficient disk space to
store the new backup(s). HTH.
> -- Garrett Taylor wrote: --
> This is the error I get for the database
named, "NoteServe4005". I get this error for all databases
whether I attempt to backup manually or automatically.
> [4] Database NoteServe4005: Transaction Log Backup...
> Destination: [c:\backup\NoteServe4005
\NoteServe4005_tlog_200405041500.TRN]
> [Microsoft SQL-DMO (ODBC SQLState: 42000)] Error
3241: [Microsoft][ODBC SQL Server Driver][SQL Server]The
media family on device 'c:\backup\NoteServe4005
\NoteServe4005_tlog_200405041500.TRN' is incorrectly
formed. SQL Server cannot process this media family.
> [Microsoft][ODBC SQL Server Driver][SQL Server]
BACKUP LOG is terminating abnormally.
> I searched support for the error pulling up only
KB:297104 which says that this can happen when transaction
log files exceed 4GB. However, the T-Log in this example
is only 50MB. It also says the error is fixed by SP1 and I
have SP3a. There's also a workaround which involves
setting the trace flag to 3111, but that didn't seem to
make a difference either.
> Ideas?
>.
>

Error backing up Transaction Logs

This is the error I get for the database named, "NoteServe4005". I get this error for all databases whether I attempt to backup manually or automatically.
[4] Database NoteServe4005: Transaction Log Backup...
Destination: [c:\backup\NoteServe4005\NoteServe4005_tlog_200405 041500.TRN]
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 3241: [Microsoft][ODBC SQL Server Driver][SQL Server]The media family on device 'c:\backup\NoteServe4005\NoteServe4005_tlog_200405 041500.TRN' is incorrectly formed. SQL Server cannot process this media fami
ly.
[Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP LOG is terminating abnormally.
I searched support for the error pulling up only KB:297104 which says that this can happen when transaction log files exceed 4GB. However, the T-Log in this example is only 50MB. It also says the error is fixed by SP1 and I have SP3a. There's also a worka
round which involves setting the trace flag to 3111, but that didn't seem to make a difference either.
Ideas?
If this file "c:\backup\NoteServe4005\NoteServe4005_tlog_200405 041500.TRN" exists, delete it.Make sure that you also have sufficient disk space to store the new backup(s). HTH.
-- Garrett Taylor wrote: --
This is the error I get for the database named, "NoteServe4005". I get this error for all databases whether I attempt to backup manually or automatically.
[4] Database NoteServe4005: Transaction Log Backup...
Destination: [c:\backup\NoteServe4005\NoteServe4005_tlog_200405 041500.TRN]
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 3241: [Microsoft][ODBC SQL Server Driver][SQL Server]The media family on device 'c:\backup\NoteServe4005\NoteServe4005_tlog_200405 041500.TRN' is incorrectly formed. SQL Server cannot process this media
family.
[Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP LOG is terminating abnormally.
I searched support for the error pulling up only KB:297104 which says that this can happen when transaction log files exceed 4GB. However, the T-Log in this example is only 50MB. It also says the error is fixed by SP1 and I have SP3a. There's also a
workaround which involves setting the trace flag to 3111, but that didn't seem to make a difference either.
Ideas?
|||The file doesn't already exist and I have more than 50GB
free where my transaction file is only 50MB.

>--Original Message--
>If this file "c:\backup\NoteServe4005
\NoteServe4005_tlog_200405041500.TRN" exists, delete
it.Make sure that you also have sufficient disk space to
store the new backup(s). HTH.
> -- Garrett Taylor wrote: --
> This is the error I get for the database
named, "NoteServe4005". I get this error for all databases
whether I attempt to backup manually or automatically.
> [4] Database NoteServe4005: Transaction Log Backup...
> Destination: [c:\backup\NoteServe4005
\NoteServe4005_tlog_200405041500.TRN]
> [Microsoft SQL-DMO (ODBC SQLState: 42000)] Error
3241: [Microsoft][ODBC SQL Server Driver][SQL Server]The
media family on device 'c:\backup\NoteServe4005
\NoteServe4005_tlog_200405041500.TRN' is incorrectly
formed. SQL Server cannot process this media family.
> [Microsoft][ODBC SQL Server Driver][SQL Server]
BACKUP LOG is terminating abnormally.
> I searched support for the error pulling up only
KB:297104 which says that this can happen when transaction
log files exceed 4GB. However, the T-Log in this example
is only 50MB. It also says the error is fixed by SP1 and I
have SP3a. There's also a workaround which involves
setting the trace flag to 3111, but that didn't seem to
make a difference either.
> Ideas?
>.
>