Showing posts with label threads. Show all posts
Showing posts with label threads. Show all posts

Saturday, February 25, 2012

"New transaction is not allowed because there are other threads running in the session." -

That is a SqlException I got at a...

at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()

Anyone an idea what THAT means? How do I cause it? How can I work around it?

I think you probably have an open connection somewhere. See if you can start the transaction after you close the connection.|||

I have about 25 open connections. Because that is - quess what - an ASP.NET application.

Once connection per page.

And every page has - one thread. No multi threading at all.

Plus it is legal for a thread to have multiple open connections.

|||

Have you enabled Multiple Active Resultsets (MARS)?

For connections with MARS enabled, manual transactions started via TSQL BEGIN TRAN must end (COMMIT or ROLLBACK) within the same scope that started the transaction

If your issue meets the the aboving conditions, you can try this work aroud:

To begin tansactions that are not required to be scoped under
MARS-enabled connections, use the client driver API constructs to begin and end transactions. If existing code relies on BEGIN TRAN operations without
corresponding COMMIT/ROLLBACK, MARS can be turned off until the application can be modified to use the client driver transaction APIs

|||Nope, no MARS. Actually that was (not is) old SQL Server 2000 code from .NET 1.1 that was traansported over. Worked flawlessly under .NET 1.1, and looks flawless to me still.

Saturday, February 11, 2012

"craxdrt9.dll" version "9.2.3.1368" errors at runtime with multiple threads STA

"craxdrt9.dll" version "9.2.3.1368" errors at runtime with multiple threads with ApartmentState as STA or MTA

I would appreciate any help on the following:

Keep getting the the following error from "Crystal Reports":

- Using "C:\Program Files\Crystal Decisions\Report Designer Component\craxdrt9.dll" version "9.2.3.1368"

Error on using multiple threads with thread.ApartmentState = ApartmentState.STA:

Object reference not set to an instance of an object.
at CRAXDRT.DatabaseTableClass.SetPrivateData(Int32 dataTag, Object data)
at TestCrystalReports1.QCrystalReports.QCrystalReportObject.processReport(IReport& iReport, Hashtable collReportDataRs, Boolean& m_btnCancelPressed) in E:\QECM\Tools\ReportingTools\TestApps\TestCrystalReports1\QCrystalReports\QCrystalReportObject.cs:line 127
at TestCrystalReports1.QCrystalReports.QCrystalReportObject.processSubReport(IReport& iReport, Hashtable collReportDataRs, Boolean& m_btnCancelPressed) in E:\QECM\Tools\ReportingTools\TestApps\TestCrystalReports1\QCrystalReports\QCrystalReportObject.cs:line 179
at TestCrystalReports1.QCrystalReports.QCrystalReportObject.runPrintJob(String rptFilePathStr, Hashtable recordsetHashTable) in E:\QECM\Tools\ReportingTools\TestApps\TestCrystalReports1\QCrystalReports\QCrystalReportObject.cs:line 81
at TestCrystalReports1.PrintRequest.runPrintRequest() in E:\QECM\Tools\ReportingTools\TestApps\TestCrystalReports1\PrintRequest.cs:line 79

Error on using multiple threads with thread.ApartmentState = ApartmentState.STA or ApartmentState.MTA:

Invalid directory.
at CRAXDRT.ApplicationClass.OpenReport(String pFileName, Object OpenMethod)
at TestCrystalReports1.QCrystalReports.QCrystalReportObject.runPrintJob(String rptFilePathStr, Hashtable recordsetHashTable) in E:\QECM\Tools\ReportingTools\TestApps\TestCrystalReports1\QCrystalReports\QCrystalReportObject.cs:line 77
at TestCrystalReports1.PrintRequest.runPrintRequest() in E:\QECM\Tools\ReportingTools\TestApps\TestCrystalReports1\PrintRequest.cs:line 79

Code extract - C# / .net application:

References: Interop.CRAXDRT.dll

- Thread running the "processReport" method - ApartmentState - tried both STA & MTA
- Problem usually occurs in case of multiple threads or multiple calls within a thread

private static int DATA_INPUT_TYPE_ADO = 3;

private void processReport (
ref IReport iReport, // Report instance
System.Collections.Hashtable collReportDataRs, // Report data
ref bool m_btnCancelPressed // Cancel button
)
{
// Get the database
IDatabase iDatabase = (IDatabase) iReport.Database;

// Get the database tables
IDatabaseTables iDatabaseTables = (IDatabaseTables) iDatabase.Tables;

// Loop through the tables
int iTotalTables = iDatabaseTables.Count;
for ( int iTblCount = 1; iTblCount <= iTotalTables; ++iTblCount )
{
if ( m_btnCancelPressed == true )
return;

// Get table name
IDatabaseTable iDatabaseTable = (IDatabaseTable) iDatabaseTables[iTblCount];

// Get the relevant recordset from the collection passed
System.String bsTableName = iDatabaseTable.Name;

ADODB._Recordset rs = (ADODB._Recordset) collReportDataRs [ bsTableName ];
if ( rs == null )
{
throw new Exception( "Data not found: " + bsTableName );
}

// Set data for this table
iDatabaseTable.SetPrivateData( DATA_INPUT_TYPE_ADO, rs);
}
}Are any of Dlls missing?
See if you find asnwer here
http://support.businessobjects.com/