Hi,
i have the following problem. I want to access some SQL output parameter
via my c# code.
The procedure looks like:
CREATE PROCEDURE sp_DoSome
@VALUE int output,@OTHER nvarchar(MAX) output
AS
BEGIN
SELECT @VALUE = -198;
SELECT @OTHER = 'Works';
END
GO
And the code to access the values:
using (SqlCommand com = new SqlCommand
{ CommandType = CommandType.StoredProcedure,
CommandText = "sp_AskForUpdate",
Connection = _connection })
{
com.Parameters.AddWithValue("@VALUE", SqlDbType.Int);
com.Parameters.AddWithValue("@OTHER", SqlDbType.NVarChar);
com.Parameters["@VALUE"].Direction = ParameterDirection.Output;
com.Parameters["@OTHER"].Direction = ParameterDirection.Output;
_connection.Open();
com.ExecuteNonQuery();
temp = com.Parameters["@VALUE"].Value.ToString() + com.Parameters["@OTHER"].Value;
_connection.Close();
}
....goes on
Doing this just with int's works fine. But in all other cases generates an exception
like this (nvarchar):
04/11/2013 11:10:00 Error converting data type nvarchar(max) to int.Void OnError(System.Data.SqlClient.SqlException, Boolean, System.Action`1[System.Action])System.Data.SqlClient.SqlException (0x80131904): Error converting data type nvarchar(max) to int.
bei System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
bei System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
bei System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
bei System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
bei System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
bei System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
bei System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
bei System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
bei JuloGroupService.Service1.AskForUpdate(Int32 companyId, Int32 miaId, Boolean& free) in C:\Users\schafmann\Desktop\visual studio 2010\Projects\JuloGroupService\JuloGroupService\Service1.svc.cs:Zeile 331.
ClientConnectionId:d955c0e9-079a-452c-8538-005e91776d3a
I dont understand why this generates a converting error???
Thanks for any help
Andree