473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

InvalidApartmentStateChange 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 RuntimeCallableWrappers 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)
{ threadedPoolInsFunction ((string)state); };
ThreadPool.QueueUserWorkItem(callback, insSqlcmd);
private static void threadedPoolInsFunction(string sybaseCmd)
{
//insert into sybase and capturing threadpool exception
try
{
AseHelper.ExecuteNonQueryCmd(sybasePtsConnString,
sybaseCmd);
}
catch (Exception eT)
{
...
}
}

//utilities
public static void ExecuteNonQueryCmd(string connectionString,string
cmdText)
{
if( connectionString == null || connectionString.Length == 0 ) throw
new ArgumentNullException( "connectionString" );
if( cmdText == null || cmdText.Length == 0 ) throw new
ArgumentNullException( "bad cmdText");
using (AseConnection connection = new
AseConnection(connectionString))
{
connection.Open();
ExecuteNonQueryCmd(connection,cmdText);
connection.Close();
}
}

Throws the thread exception on connection.Close();

Any ideas?

Thanks


*** Sent via Developersdex http://www.developersdex.com ***
Feb 7 '06 #1
2 2828
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**************@TK2MSFTNGP15.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 RuntimeCallableWrappers 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)
{ threadedPoolInsFunction ((string)state); };
ThreadPool.QueueUserWorkItem(callback, insSqlcmd);
private static void threadedPoolInsFunction(string sybaseCmd)
{
//insert into sybase and capturing threadpool exception
try
{
AseHelper.ExecuteNonQueryCmd(sybasePtsConnString,
sybaseCmd);
}
catch (Exception eT)
{
...
}
}

//utilities
public static void ExecuteNonQueryCmd(string connectionString,string
cmdText)
{
if( connectionString == null || connectionString.Length == 0 ) throw
new ArgumentNullException( "connectionString" );
if( cmdText == null || cmdText.Length == 0 ) throw new
ArgumentNullException( "bad cmdText");
using (AseConnection connection = new
AseConnection(connectionString))
{
connection.Open();
ExecuteNonQueryCmd(connection,cmdText);
connection.Close();
}
}

Throws the thread exception on connection.Close();

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**************@TK2MSFTNGP15.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 RuntimeCallableWrappers 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)
| { threadedPoolInsFunction ((string)state); };
| ThreadPool.QueueUserWorkItem(callback, insSqlcmd);
|
|
| private static void threadedPoolInsFunction(string sybaseCmd)
| {
| //insert into sybase and capturing threadpool exception
| try
| {
| AseHelper.ExecuteNonQueryCmd(sybasePtsConnString,
| sybaseCmd);
| }
| catch (Exception eT)
| {
| ...
| }
| }
|
| //utilities
| public static void ExecuteNonQueryCmd(string connectionString,string
| cmdText)
| {
| if( connectionString == null || connectionString.Length == 0 ) throw
| new ArgumentNullException( "connectionString" );
| if( cmdText == null || cmdText.Length == 0 ) throw new
| ArgumentNullException( "bad cmdText");
| using (AseConnection connection = new
| AseConnection(connectionString))
| {
| connection.Open();
| ExecuteNonQueryCmd(connection,cmdText);
| connection.Close();
| }
| }
|
| Throws the thread exception on connection.Close();
|
| 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
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...
6
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: ...
0
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
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...
3
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...
4
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 =...
32
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
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...
0
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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,...

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.