Threading problem

S

Suhail Salman

Dear All,

i got the following error message in an applications that opens 13
threads and all of them calling a stored procedure which retreieves data
from SQLServer and fills them to a table the error appears at the following
statment
sqlda.Fill(dtMessages);

During an infinit loopp

------



while(true)

{

#region While Body

ReConnect:

// check connectbion status and retry to connect in case of open failure


sqlcmd.Parameters["@cusDate"].Value=DateTime.Now;

sqlcmd.Parameters["@cusTime"].Value=DateTime.Now.ToString("HH:mm");

SqlDataAdapter sqlda;

DataTable dtMessages=new DataTable();

RECHECK:

try

{

sqlda=new SqlDataAdapter(sqlcmd); // have to put it here although of the
perfomance leak

Application.DoEvents();

sqlda.Fill(dtMessages);

Application.DoEvents();

lblSQLConnectionStatus.ForeColor=System.Drawing.Color.SteelBlue;

lblSQLConnectionStatus.Text="OnLine";

}

catch(Exception ex)

{

ApplicationSettingsCLL.ApplicationSettings.logEvent(System.Diagnostics.Event
LogEntryType.Error,"Communication error with SQL
Server\nError:"+ex.Message+"\nStack Trace:"+ex.StackTrace);

lblSQLConnectionStatus.ForeColor=System.Drawing.Color.Tomato;

lblSQLConnectionStatus.Text="OFFLINE!!";

Thread.Sleep(2000);

goto RECHECK;

}

. . . .

}

------------
the error message is
Thread was being aborted.

stack trace :
Stack Trace:
at System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext, Boolean WaitAll)
at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext)
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection,
ConnectionState& originalState)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDbCommand
command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

It seems that you are getting all the available connections from the pool
Anyway IMHO the code would need a few changes, I did not understand what
are you trying to do but if this is the code that runs on the threads and
lblSQLConnectionStatus is a label that is is declared on the main thread you
cannot change it from the working threads.

BTW I had not seen a goto in a long time ;)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Suhail Salman said:
Dear All,

i got the following error message in an applications that opens 13
threads and all of them calling a stored procedure which retreieves data
from SQLServer and fills them to a table the error appears at the following
statment
sqlda.Fill(dtMessages);

During an infinit loopp

------



while(true)

{

#region While Body

ReConnect:

// check connectbion status and retry to connect in case of open failure


sqlcmd.Parameters["@cusDate"].Value=DateTime.Now;

sqlcmd.Parameters["@cusTime"].Value=DateTime.Now.ToString("HH:mm");

SqlDataAdapter sqlda;

DataTable dtMessages=new DataTable();

RECHECK:

try

{

sqlda=new SqlDataAdapter(sqlcmd); // have to put it here although of the
perfomance leak

Application.DoEvents();

sqlda.Fill(dtMessages);

Application.DoEvents();

lblSQLConnectionStatus.ForeColor=System.Drawing.Color.SteelBlue;

lblSQLConnectionStatus.Text="OnLine";

}

catch(Exception ex)

{

ApplicationSettingsCLL.ApplicationSettings.logEvent(System.Diagnostics.Event
LogEntryType.Error,"Communication error with SQL
Server\nError:"+ex.Message+"\nStack Trace:"+ex.StackTrace);

lblSQLConnectionStatus.ForeColor=System.Drawing.Color.Tomato;

lblSQLConnectionStatus.Text="OFFLINE!!";

Thread.Sleep(2000);

goto RECHECK;

}

. . . .

}

------------
the error message is
Thread was being aborted.

stack trace :
Stack Trace:
at System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext, Boolean WaitAll)
at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext)
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection,
ConnectionState& originalState)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDbCommand
command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
 
S

Suhail Salman

thanks for helping Ignacio,


lblSQLConnectionStatus is a label that is defined in the working thread, and defined also in the main thread, actually the calling thread (main thread) when calling the constructor of the working thread it passes the actual label as an input to the constructor
public RRInterface(Label InternetConnectionStatusLabel,string strConnectionString,Label SQLConnectionStatus,Label FastLinkConnectionStatus)

{

lblInternetConnectionStatus=InternetConnectionStatusLabel;

lblSQLConnectionStatus=SQLConnectionStatus;

lblFastLinkConnectionStatus=FastLinkConnectionStatus;

sqlCon=new SqlConnection(strConnectionString);

cFastlink=new CFastLinkConnection();

}

as for the connection pool, am initializing the sql connection string to enable a pool maximum size of 50...
the SQL connection string is below, am initializing 13 threads only so how it comes that i consume this pool, and i even tried to set the size to 100 and its still the same

"Provider=SQLOLEDB;data source=193.1.1.1;user id=sa;password=;Trusted_Connection=no;connection reset=false;connection lifetime=5;Initial Catalog=eBanking;enlist=true;min pool size=1;max pool size=50"


thanks again
if it helps better i can email this class to u...

regards,
Suhail

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

It seems that you are getting all the available connections from the pool
Anyway IMHO the code would need a few changes, I did not understand what
are you trying to do but if this is the code that runs on the threads and
lblSQLConnectionStatus is a label that is is declared on the main thread you
cannot change it from the working threads.

BTW I had not seen a goto in a long time ;)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Suhail Salman said:
Dear All,

i got the following error message in an applications that opens 13
threads and all of them calling a stored procedure which retreieves data
from SQLServer and fills them to a table the error appears at the following
statment
sqlda.Fill(dtMessages);

During an infinit loopp

------



while(true)

{

#region While Body

ReConnect:

// check connectbion status and retry to connect in case of open failure


sqlcmd.Parameters["@cusDate"].Value=DateTime.Now;

sqlcmd.Parameters["@cusTime"].Value=DateTime.Now.ToString("HH:mm");

SqlDataAdapter sqlda;

DataTable dtMessages=new DataTable();

RECHECK:

try

{

sqlda=new SqlDataAdapter(sqlcmd); // have to put it here although of the
perfomance leak

Application.DoEvents();

sqlda.Fill(dtMessages);

Application.DoEvents();

lblSQLConnectionStatus.ForeColor=System.Drawing.Color.SteelBlue;

lblSQLConnectionStatus.Text="OnLine";

}

catch(Exception ex)

{

ApplicationSettingsCLL.ApplicationSettings.logEvent(System.Diagnostics.Event
LogEntryType.Error,"Communication error with SQL
Server\nError:"+ex.Message+"\nStack Trace:"+ex.StackTrace);

lblSQLConnectionStatus.ForeColor=System.Drawing.Color.Tomato;

lblSQLConnectionStatus.Text="OFFLINE!!";

Thread.Sleep(2000);

goto RECHECK;

}

. . . .

}

------------
the error message is
Thread was being aborted.

stack trace :
Stack Trace:
at System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext, Boolean WaitAll)
at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext)
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection,
ConnectionState& originalState)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDbCommand
command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Remember that the connection has two points, what about the Sql point? maybe your SQl server does not support more than 10 connections, in any case I think that your problem must be related to it, a look at the stacktrace indicate that.

The label is defined on the main thread, you may have access to it from the working thread but it's defined on the main thread, therefore you should use Control.Invoke to make changes to it.

And why are you using 13 threads, did you try to use less threads and do more on each thread?

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

thanks for helping Ignacio,


lblSQLConnectionStatus is a label that is defined in the working thread, and defined also in the main thread, actually the calling thread (main thread) when calling the constructor of the working thread it passes the actual label as an input to the constructor
public RRInterface(Label InternetConnectionStatusLabel,string strConnectionString,Label SQLConnectionStatus,Label FastLinkConnectionStatus)

{

lblInternetConnectionStatus=InternetConnectionStatusLabel;

lblSQLConnectionStatus=SQLConnectionStatus;

lblFastLinkConnectionStatus=FastLinkConnectionStatus;

sqlCon=new SqlConnection(strConnectionString);

cFastlink=new CFastLinkConnection();

}

as for the connection pool, am initializing the sql connection string to enable a pool maximum size of 50...
the SQL connection string is below, am initializing 13 threads only so how it comes that i consume this pool, and i even tried to set the size to 100 and its still the same

"Provider=SQLOLEDB;data source=193.1.1.1;user id=sa;password=;Trusted_Connection=no;connection reset=false;connection lifetime=5;Initial Catalog=eBanking;enlist=true;min pool size=1;max pool size=50"


thanks again
if it helps better i can email this class to u...

regards,
Suhail

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

It seems that you are getting all the available connections from the pool
Anyway IMHO the code would need a few changes, I did not understand what
are you trying to do but if this is the code that runs on the threads and
lblSQLConnectionStatus is a label that is is declared on the main thread you
cannot change it from the working threads.

BTW I had not seen a goto in a long time ;)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Suhail Salman said:
Dear All,

i got the following error message in an applications that opens 13
threads and all of them calling a stored procedure which retreieves data
from SQLServer and fills them to a table the error appears at the following
statment
sqlda.Fill(dtMessages);

During an infinit loopp

------



while(true)

{

#region While Body

ReConnect:

// check connectbion status and retry to connect in case of open failure


sqlcmd.Parameters["@cusDate"].Value=DateTime.Now;

sqlcmd.Parameters["@cusTime"].Value=DateTime.Now.ToString("HH:mm");

SqlDataAdapter sqlda;

DataTable dtMessages=new DataTable();

RECHECK:

try

{

sqlda=new SqlDataAdapter(sqlcmd); // have to put it here although of the
perfomance leak

Application.DoEvents();

sqlda.Fill(dtMessages);

Application.DoEvents();

lblSQLConnectionStatus.ForeColor=System.Drawing.Color.SteelBlue;

lblSQLConnectionStatus.Text="OnLine";

}

catch(Exception ex)

{

ApplicationSettingsCLL.ApplicationSettings.logEvent(System.Diagnostics.Event
LogEntryType.Error,"Communication error with SQL
Server\nError:"+ex.Message+"\nStack Trace:"+ex.StackTrace);

lblSQLConnectionStatus.ForeColor=System.Drawing.Color.Tomato;

lblSQLConnectionStatus.Text="OFFLINE!!";

Thread.Sleep(2000);

goto RECHECK;

}

. . . .

}

------------
the error message is
Thread was being aborted.

stack trace :
Stack Trace:
at System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext, Boolean WaitAll)
at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext)
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection,
ConnectionState& originalState)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDbCommand
command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top