473,730 Members | 2,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InvalidApartmen tStateChange was detected - any ideas

GG
I have a thread pool that calls a sybase function and getting this
message

The current thread used to have an apartment state of MTA,
but the application has CoUnitialized this thread and it is now STA.
This may cause calls on RuntimeCallable Wrappers representing some
COM components to fail and may also cause COM component
that are not multi-threaded to be accessed from multiple threads
at the same time which can cause corruption or data loss.
these are the parts
//add work to thread
WaitCallback callback = delegate (object state)
{ threadedPoolIns Function ((string)state) ; };
ThreadPool.Queu eUserWorkItem(c allback, insSqlcmd);
private static void threadedPoolIns Function(string sybaseCmd)
{
//insert into sybase and capturing threadpool exception
try
{
AseHelper.Execu teNonQueryCmd(s ybasePtsConnStr ing,
sybaseCmd);
}
catch (Exception eT)
{
...
}
}

//utilities
public static void ExecuteNonQuery Cmd(string connectionStrin g,string
cmdText)
{
if( connectionStrin g == null || connectionStrin g.Length == 0 ) throw
new ArgumentNullExc eption( "connectionStri ng" );
if( cmdText == null || cmdText.Length == 0 ) throw new
ArgumentNullExc eption( "bad cmdText");
using (AseConnection connection = new
AseConnection(c onnectionString ))
{
connection.Open ();
ExecuteNonQuery Cmd(connection, cmdText);
connection.Clos e();
}
}

Throws the thread exception on connection.Clos e();

Any ideas?

Thanks


*** Sent via Developersdex http://www.developersdex.com ***
Feb 7 '06 #1
2 2843
Hi,

Looks like Sybase code is too smart to manage the calling thread's apartment
state (which I believe it shouldn't do). What if you try to run the same
code on a manually created thread?

<GG> wrote in message news:ed******** ******@TK2MSFTN GP15.phx.gbl...
I have a thread pool that calls a sybase function and getting this
message

The current thread used to have an apartment state of MTA,
but the application has CoUnitialized this thread and it is now STA.
This may cause calls on RuntimeCallable Wrappers representing some
COM components to fail and may also cause COM component
that are not multi-threaded to be accessed from multiple threads
at the same time which can cause corruption or data loss.
these are the parts
//add work to thread
WaitCallback callback = delegate (object state)
{ threadedPoolIns Function ((string)state) ; };
ThreadPool.Queu eUserWorkItem(c allback, insSqlcmd);
private static void threadedPoolIns Function(string sybaseCmd)
{
//insert into sybase and capturing threadpool exception
try
{
AseHelper.Execu teNonQueryCmd(s ybasePtsConnStr ing,
sybaseCmd);
}
catch (Exception eT)
{
...
}
}

//utilities
public static void ExecuteNonQuery Cmd(string connectionStrin g,string
cmdText)
{
if( connectionStrin g == null || connectionStrin g.Length == 0 ) throw
new ArgumentNullExc eption( "connectionStri ng" );
if( cmdText == null || cmdText.Length == 0 ) throw new
ArgumentNullExc eption( "bad cmdText");
using (AseConnection connection = new
AseConnection(c onnectionString ))
{
connection.Open ();
ExecuteNonQuery Cmd(connection, cmdText);
connection.Clos e();
}
}

Throws the thread exception on connection.Clos e();

Any ideas?

Thanks


*** Sent via Developersdex http://www.developersdex.com ***

Feb 8 '06 #2
Where do you get this message from?
If this is an exception message, could you post the call stack?
Anyway, the message should be taken seriously.

Willy.

<GG> wrote in message news:ed******** ******@TK2MSFTN GP15.phx.gbl...
|I have a thread pool that calls a sybase function and getting this
| message
|
| The current thread used to have an apartment state of MTA,
| but the application has CoUnitialized this thread and it is now STA.
| This may cause calls on RuntimeCallable Wrappers representing some
| COM components to fail and may also cause COM component
| that are not multi-threaded to be accessed from multiple threads
| at the same time which can cause corruption or data loss.
|
|
| these are the parts
| //add work to thread
| WaitCallback callback = delegate (object state)
| { threadedPoolIns Function ((string)state) ; };
| ThreadPool.Queu eUserWorkItem(c allback, insSqlcmd);
|
|
| private static void threadedPoolIns Function(string sybaseCmd)
| {
| //insert into sybase and capturing threadpool exception
| try
| {
| AseHelper.Execu teNonQueryCmd(s ybasePtsConnStr ing,
| sybaseCmd);
| }
| catch (Exception eT)
| {
| ...
| }
| }
|
| //utilities
| public static void ExecuteNonQuery Cmd(string connectionStrin g,string
| cmdText)
| {
| if( connectionStrin g == null || connectionStrin g.Length == 0 ) throw
| new ArgumentNullExc eption( "connectionStri ng" );
| if( cmdText == null || cmdText.Length == 0 ) throw new
| ArgumentNullExc eption( "bad cmdText");
| using (AseConnection connection = new
| AseConnection(c onnectionString ))
| {
| connection.Open ();
| ExecuteNonQuery Cmd(connection, cmdText);
| connection.Clos e();
| }
| }
|
| Throws the thread exception on connection.Clos e();
|
| Any ideas?
|
| Thanks
|
|
|
|
|
|
|
|
| *** Sent via Developersdex http://www.developersdex.com ***
Feb 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
28070
by: Chandika | last post by:
Hi all, One of my database was suspected, So I try to recover database then it gives this error Err. 823 Torn Page Detected 823, ... 24, spid51 i/o error Torn Page (Detected) during read at offset 0x0000000040e0000 in file .........
6
3285
by: Matt Bostock | last post by:
Hi, When I validate this page: http://www.drfunkenstein.net/using http://jigsaw.w3.org/css-validator/, I get the following results: http://jigsaw.w3.org/css-validator/validator?profile=css2&warning=2&uri=http%3A//www.drfunkenstein.net/ Or briefly: "Uncaught error java.lang.Exception: Import loop detected in
0
1246
by: Rob | last post by:
Hi I am getting the error *** glibc detected *** free(): invalid pointer: 0x083e20cc *** Aborted When I run the code <?php
3
43219
by: Tim Reynolds | last post by:
I support a .Net application running on a SERVER accessing MF Db2 data. Occasionally, we have some type of connection problem that we have been unable to debug up to this point. We typically receive one of these IBM.Data.DB2.DB2Exception messages: ERROR SQL30081N A communication error has been detected. Communication protocol being used: ‘TCP/IP'. Communication API being used: ‘SOCKETS'. Location where the error was detected:...
3
7039
by: Laura | last post by:
I've just installed the DB2 Run-time client in a Solaris machine. Then I finnish the installation configuring the connection: 1. machine catalog was OK: ========================== $ db2 catalog tcpip node atlas remote dsroracle server 8100 DB20000I The CATALOG TCPIP NODE command completed successfully. DB21056W Directory changes may not be effective until the directory cache is refreshed. 2. database catalog was OK:
4
36158
by: Ralf Gross | last post by:
Hi, I installed DB2 V8.1 with fixpak 10, created a new database and can connect to the database. $ db2 connect to mkstest Database Connection Information Database server = DB2/LINUX 8.2.3
32
5939
by: Clunixchit | last post by:
How can i read lines of a file and place each line read in an array? for exemple; array=line1 array=line2 ...
1
263
by: Mustafa Rabie | last post by:
Hi I have a Windows 2003 Server enterprise + Visual Studio 2003 + IIS 6. Creating new Web Projects and Services using VS 2K3 was working gr8. All of a sudden today i was trying to creat/open a new/existing web application and i got the following Error... dotnet framework was not detected on the serer you are contacting you cant run ASP.Net applications or services (something like that). I uninstalled IIS and ASP.Net and reinstalled them...
0
1100
by: sam.s.kong | last post by:
Hi! When I create or modify an asp file, obvious systax errors are not detected. For example: Sub MySub Response.Write "Hello" End
0
8770
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9301
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9229
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9176
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8184
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6725
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4543
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4801
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.