Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
fI have an application that calls a stored procedure. The stored procedure is supposed to query an external ODBC database for all available tables and data. There are some known tables that cause an error and I have accounted for them by wraping the execution in a TRY...CATCH block. When I run the stored procedure from SQL Management Studio it will display the errord tables and finish executing. However, when I call it from my C# application it will return a Timeout error when it hits that first error table. Is there a way to force a Stored procedure to continue to execute and not return the error to the C# applicaion?

SQL Code:
- @tableName is derived from searching all available tables in the external ODBC database.

BEGIN TRY
SET @command = ''
SELECT @command = 'SELECT * INTO [' + @tableName + '] FROM EXTERNAL DATABASE.' + @tableName
EXECUTE(@command)
END TRY
BEGIN CATCH
PRINT 'Error processing the table: ' + @tableName
END CATCH

C# Code:

sqlCommand.ExecuteNonQuery();
catch(SqlException sqle)
{
Console.WriteLine(sqle);
}
Posted
Updated 23-Feb-11 2:28am
v2

Hi,

The CATCH block is responsible of doing the proper operations. If you currently raise an error frmo DB in catch, you'll receive an error in C# but if you omit (poroper) errors the execution continues after the catch.

To answer more specific could you post the actual code along the error you receive...

mika
 
Share this answer
 
You can change the timeout in the connection string for SqlServer to wait for the connection by adding ;timeout=60 to the connection string.

You can also set the
C#
cmd.CommandTimeout=60;

Default is 30 seconds.. Better not to set it as infinite timeout (value as 0).

Try increasing the last of these until the SP runs. As a Last resort, use 0 (zero = infinite) since this would indicate there might be another problem.
 
Share this answer
 
Unfortunately, I used a GOTO :(( in the SQL Stored Procedure. If I get more time I will try to figure something better!


SQL Code:
- @tableName is derived from searching all available tables in the external ODBC database.

BEGIN TRY
SET @command = ''
SELECT @command = 'SELECT * INTO [' + @tableName + '] FROM EXTERNAL DATABASE.' + @tableName
EXECUTE(@command)
END TRY
BEGIN CATCH
PRINT 'Error processing the table: ' + @tableName
GOTO Here:
END CATCH

Here:
Continue execution!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900