[Mono-list] RETURN_VALUE from SqlClient?

Andy andypalmer@adelphia.net
Thu, 20 Jan 2005 23:00:45 -0500


Hi,
    I am trying to get a return value from a SQL 7.0 stored procedure. 
I am thinking TDS perhaps the protocol wrong? But I do not know how to 
set it under mono.

The exception I receive is:

'int' is not a recognized CURSOR option.

in <0x0011b> System.Data.SqlClient.SqlConnection:ErrorHandler 
(object,Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs)
in <0x00069> (wrapper delegate-invoke) 
System.MulticastDelegate:invoke_void_object_TdsInternalErrorMessageEventArgs 
(object,Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs)
in <0x0001e> Mono.Data.Tds.Protocol.Tds:OnTdsErrorMessage 
(Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs)
in <0x00056> (wrapper remoting-invoke-with-check) 
Mono.Data.Tds.Protocol.Tds:OnTdsErrorMessage 
(Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs)
in <0x00276> Mono.Data.Tds.Protocol.Tds:ProcessMessage 
(Mono.Data.Tds.Protocol.TdsPacketSubType)
in <0x00052> (wrapper remoting-invoke-with-check) 
Mono.Data.Tds.Protocol.Tds:ProcessMessage 
(Mono.Data.Tds.Protocol.TdsPacketSubType)
in <0x0015f> Mono.Data.Tds.Protocol.Tds:ProcessSubPacket ()
in <0x00050> Mono.Data.Tds.Protocol.Tds:NextResult ()
in <0x00089> System.Data.SqlClient.SqlDataReader:NextResult ()
in <0x0005d> (wrapper remoting-invoke-with-check) 
System.Data.SqlClient.SqlDataReader:NextResult ()
in <0x00122> System.Data.SqlClient.SqlDataReader:.ctor 
(System.Data.SqlClient.SqlCommand)
in <0x00056> (wrapper remoting-invoke-with-check) 
System.Data.SqlClient.SqlDataReader:.ctor (System.Data.SqlClient.SqlCommand)
in <0x000a2> System.Data.SqlClient.SqlCommand:ExecuteReader 
(System.Data.CommandBehavior)
in <0x00054> (wrapper remoting-invoke-with-check) 
System.Data.SqlClient.SqlCommand:ExecuteReader (System.Data.CommandBehavior)
in <0x0017d> TestReturnValue.Program:Main (string[])

Here is some code to reproduce this. I have tried ExecuteNonQuery 
without the DataReader = and with it. Any help would be greatly appreciated.

A simple stored proc:

CREATE PROCEDURE sp_ReturnValue @inVal int
AS
BEGIN
	return(@inVal)
END


static void Main(string[] args)
{
	System.Data.SqlClient.SqlConnection conn=null;
	try
	{
  	 String connstr = PUT SOMETHING HERE;
	 conn=new System.Data.SqlClient.SqlConnection(connstr);
	 conn.Open();
	 System.Data.SqlClient.SqlCommand  cmd=
                new System.Data.SqlClient.SqlCommand();
	 cmd.CommandText = "sp_ReturnValue";
	 cmd.CommandType =  System.Data.CommandType.StoredProcedure;
	 cmd.Connection = conn;
	 SqlParameter parm=
             cmd.Parameters.Add("@inVal",System.Data.SqlDbType.Int);
	 parm.Value = 2;
	 parm = cmd.Parameters.Add("RETURN_VALUE",
                                    System.Data.SqlDbType.Int);
          parm.Direction = System.Data.ParameterDirection.ReturnValue;
				
	System.Data.SqlClient.SqlDataReader rs =
             cmd.ExecuteReader();
	int x = cmd.ExecuteNonQuery();		
	System.Int32 x =
            (System.Int32)cmd.Parameters["RETURN_VALUE"].Value;
	Console.WriteLine(x);
	rs.Close();
	cmd.Parameters.Clear();
	conn.Close();
	}
	catch(Exception e)
	{
	  Console.WriteLine(e.StackTrace);
	  Console.WriteLine(e.Message);
         }
         finally
	{
	  try {	conn.Close(); }	catch(Exception e){};
	}
}

andy


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.1 - Release Date: 1/19/2005