Re: Random Timeout Exceptions

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Yuriy Solodkyy (sw_at_softasap-something-to-remove.com)
Date: 06/06/04


Date: Sun, 6 Jun 2004 16:04:01 +0300

It seems that the problem is actual only for some software configurations.
There are severs where it always fails and where it works fine.

"Yuriy Solodkyy" <swNOSPAM@softasapPLEASE.com> wrote in message
news:eZXeFu6SEHA.3724@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> the following problem was raised several times in newsgroups, but I still
> cannot find suitable solution.
> Let say we have the following stored procedure which returns many records.
> (this is only a sample, it does not do
> anything meaningful)
>
> -- ================================
>
> create procedure a as begin
>
> declare @a table (a int)
>
> declare @i int set @i = 0
>
>
> while @i < 11 begin
> insert into @a(a) values (@i)
> insert into @a select a from @a
> set @i = @i + 1
> end
>
> select a.a from @a a , @a b
>
> end
> -- ================================
>
> I have created it in pubs DB. If you run it in query analyzer you will get
> results soon.
>
> If you run the follwing C# program you also get it completed soon.
> (You may have to change connection string.)
>
> ////////////////////////////////
> using System;
> using System.Data.SqlClient;
>
> namespace TestApp {
> class TestApp {
>
> [STAThread]
> static void Main(string[] args) {
> using (SqlConnection c = new SqlConnection(@"Integrated
> Security=SSPI;Initial Catalog=pubs;Data Source=localhost;")) {
> c.Open();
> using (SqlCommand m = new SqlCommand(@"execute a", c)) {
> m.CommandTimeout = 0;
> using (SqlDataReader r =
> m.ExecuteReader(System.Data.CommandBehavior.SequentialAccess)) {
> int i = 0;
> for (;;) {
> while (r.Read()) {
> i++;
> if ((i % 123456) == 0) Console.Write(".");
> }
> if (!r.NextResult()) break;
> };
> }
> }
> }
> Console.WriteLine("completed!");
> }
>
> }
> }
> ///////////////////////////
>
> However, if you start two instances of this code in two simultaniously
> running threads you randomly get exceptions
> with message: "Timeout expired. The timeout period elapsed prior to
> completion of the operation or the server is
> not responding."
>
> The code below illustrates this. It starts 2 threads. It is not enough to
> get error on some computers, so increase
> thread count to 3 or 4. If you have hypethreaded computer ot
multiprocessor
> system a chance of getting error is
> higher.
>
> "*" in application output means catching this exception.
>
> ////////////////////////
> using System;
> using System.Data.SqlClient;
>
> namespace TestApp {
> class TestApp {
>
> [STAThread]
> static void Main(string[] args) {
> System.Threading.Thread t;
> for(int j = 0; j < 2; j++) {
> t = new System.Threading.Thread(new
> System.Threading.ThreadStart(ThreadProc));
> t.Start();
> }
> }
>
> public static void ThreadProc() {
> // repeats reading..
> while (true) {
> DoTest();
> }
> }
>
> public static void DoTest() {
> try {
> using (SqlConnection c = new SqlConnection(@"Integrated
> Security=SSPI;Initial Catalog=pubs;Data Source=localhost;")) {
> c.Open();
> using (SqlCommand m = new SqlCommand(@"execute a", c)) {
> m.CommandTimeout = 0;
> using (SqlDataReader r =
> m.ExecuteReader(System.Data.CommandBehavior.SequentialAccess)) {
> int i = 0;
> for (;;) {
> while (r.Read()) {
> i++;
> if ((i % 123456) == 0) Console.Write(".");
> }
> if (!r.NextResult()) break;
> };
> }
> }
> }
> Console.WriteLine("completed!");
> }
> catch (Exception e){
> if (e.Message == "Timeout expired. The timeout period elapsed
prior
> to completion of the operation or the server is not responding.") {
> Console.Write("*");
> }
> else {
> Console.WriteLine("*************" + e.Message);
> Console.WriteLine(e.StackTrace);
> }
> }
> }
>
>
> }
> }
>
> //////////////////////////////////
>
> Usual output is:
>
>
...............................**...........................................
> ....
>
.....................................................................*.*....
> ....
>
............................................................................
> ....
>
...........................................................*.....*..........
> ....
>
............................................................................
> ....
>
............................................................................
> ....
>
..........................................*.................................
> ....
> ..................completed!
>
....................................................*.......................
> ....
>
............................*...............................................
> ....
>
............................................................................
> ....
> .....................................................
>
> Here "completed!" means that thread was able to read all data without
> exception. I haven't seen this message on
> hyperthread systems.
> Does anybody know how to avoid getting this exception?
>
> Thank you in advance,
> Yuriy
>
>
>
>
>
>
>



Relevant Pages

  • Random Timeout Exceptions
    ... Let say we have the following stored procedure which returns many records. ... namespace TestApp { ... "*" in application output means catching this exception. ... Usual output is: ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Sending email
    ... I'm even newer to programming email ... using whatever arguments it needs -- uses sendEmail ... line throws an exception, your mailmenssage will never be disposed of. ... public static void forgotPassword ...
    (microsoft.public.dotnet.languages.csharp)
  • How to get the value of an attribute in an XML node?
    ... of an xml file that I am trying to read and get the values of the ... XMLEventReader r = factory.createXMLEventReader; ... catch (Exception ex) ... public static void getGeneRecord{ ...
    (comp.lang.java.databases)
  • Re: FILESYS exception with hive registry in 4.2
    ... thanks for responding. ... debug mode. ... > It appears that urlmon is passing -1 to RegCloseKey. ... > using exception handling. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Is It Possible to Make Java Find a File on Your Computer?
    ... The fact that Desktop respects local behavior associations makes it most ... public static void mainthrows Exception { ... public class FileAssociation { ...
    (comp.lang.java.programmer)