I have a strange problem calling a stored procedure from c# code.
This is the scenario:
I have a DB browser application with which I run different kinds of queries on a SQL Server DB (eg. Select, Update, execute stored procedure...)
So in my app I have an edit window where i write the T-SQL text that I run with this code:
IDbCommand command = connection.CreateCommand();
command.Connection = connection;
command.CommandTimeout = connection.CommandTimeout;
command.CommandType = CommandType.Text;
command.CommandText = textBoxQuery.Text
IDbReader reader = command.ExecuteReader();
And I have a stored procedure with a structure like:
CREATE PROCEDURE dbo.test (@a as int)
if @a=1 begin
exec test @a
(obviously this is just the prototype of a real SP that does something)
A simple test procedure that should fail with maximum nesting exception with @a=1 and just print something with any other value.
I try to run the following query:
exec test 0
I get an SqlException for maximum nesting level reached
Actually I get this exception for any value I pass to the SP! To be sure that the value is passed correctly, I commented out the recursion part, and the correct value is printed.
If I run the same query in Management Studio it runs correctly with any value, and fails only with @a=1
I don't have any clue on what is happening... any advice?