Friday, 6 September 2013

System.Data.SqlClient fails when SQL Server Management Studio succeeds

System.Data.SqlClient fails when SQL Server Management Studio succeeds

I expect discussions to be more speculative than definitive, because the
issue is rather speculative itself. It is rather confounding in nature.
I'm looking at .NET 4.0 C# code that utilizes
Microsoft.Practices.EnterpriseLibrary for SQL Server data access.
The code calls a stored procedure which runs well in SQL Server Management
Studio and returns results. The problem is, when the procedure is called
in from the C# side, an exception is thrown.
The offending code is as follows:
Database _db = DatabaseFactory.CreateDatabase(instance_name);
string _sql = "[dbo].[usp_stored_procedure]";
DbCommand _cmd = _db.GetStoredProcCommand(_sql);
/* _db.AddInParameter calls to supply parameters */
DataSet _ds = _db.ExecuteDataSet(_cmd);
The last line throws an exception, that says:
Arithmetic overflow error converting int to data type numeric.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection)
....
at System.Data.SqlClient.SqlDataReader.Read()
....
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
....
at
Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteDataSet(DbCommand
command)
....
at DataAccess.call_stored_procedure (string instance_name, int?
_client_id, int? _client_group_id, int? _event_type_id, DateTime
_start_date, DateTime _end_date, int? _employee_type_id, int? _survey_id,
int? _ro_date )
I've omitted (what I amass to be) unnecessary stack trace, and the
function in which the exception is thrown. The arguments are supplied in
that order, and the types match precisely.
There are usages of Decimal(18, 10) in the stored procedure, and the
stored procedure works with a previous set of data (and on C# side as
well) It creates problem with the new supply of data.
My "question" is if this sort of behavior is a known issue, or where to
start looking. It seems bizarre that what works in SQL Server Management
Studio does not in C# code invocation.

No comments:

Post a Comment