views:

26

answers:

2

I have problem with Timeout, when I run a command through app, a timeout exception is thrown, but when I run it directly in sql there is no timeout exception!

my SP take about 11 min when I run it directly. for solving this issue, I found below code here, but It doesn't work properly! Immediately after beginExecute, IAsyncResult.iscomplete become true !!!!

where is the problem ?

IAsyncResult result = command.BeginExecuteNonQuery();

    int count = 0;
    while (!result.IsCompleted)
    {
        Console.WriteLine("Waiting ({0})", count++);
        System.Threading.Thread.Sleep(1000);
    }
    Console.WriteLine("Command complete. Affected {0} rows.",
    command.EndExecuteNonQuery(result));

regards

A: 

A connection string will default to a 15 second timeout. See on MSDN.

You can change the timeout on the connection string to last longer (connection timeout=600, for a 10 minute timeout).

See this site for more about connection strings.

Having said that, you should look at optimizing your database and/or stored procedure. 11 minutes for a stored procedure is very very long. Do you have the correct indexes on your tables? Is you stored procedure written in the most optimal way?

Update:

Have you made sure you are using the correct command and that the results are correct? IsComplete being true almost immediately suggests that the command has indeed finished.

Oded
Thanks for answering,I increased timeout in connection string but it did not work.in this sp I have to work on 3 table hierarchically,I have 3 cursor and used them hierarchically for this 3 table!
Alibm
@Alibm - What is wrong with 3 joins instead of the cursors?
Oded
I have to read all of these record and insert them for newyaer so I need new IDs for child tables
Alibm
A: 

Increase the command timeout instead (SqlCommand.CommandTimeout) which by default is 30 seconds.

Mehmet Aras
I did not know that there is a another timeout in Command!Thanks, My main problem is solved!But what happen to IAsync ?
Alibm
Are you getting any results? What are you specifying as the command text?
Mehmet Aras