Question

I'm working on converting a rather complex .NET WinForms program into a fully-integrated SQL Server set of sprocs and functions.

I'm working on a 3rd party database over which I have no control at all.

The unique identifiers used throughout this database are all numeric(21). It doesn't matter if that's a good idea or not... I have to work within that constraint.

I'm having trouble figuring out how to code functions that use these values. So far, I'm using System.Decimal to do so, which appears to work fine when the code is called from within the .dll itself.

In SSMS, however, when I inspect any of the functions, the input parameter data type is numeric(18,0). I'm assuming it is assuming that based on the System.Decimal type, but that's wrong. And the end result is that when I try to call the function manually (in SSMS), I get the following error:

Arithmetic overflow error converting numeric to data type numeric.

The weird thing is that the calls DON'T fail when I call the functions from within the .dll. How can I override the numeric(18,0) designation?

Was it helpful?

Solution

Man, I hate it when further googling finds the answer like 30 seconds after I post a question!!!

I swear, I've been looking at this for days...

Anyway, I needed to add a SqlFacet to my input parameter.

I went from this:

<Microsoft.SqlServer.Server.SqlProcedure()> 
Public Shared Sub Check(ByVal ID As Decimal)

To this:

<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Shared Sub Check(<SqlFacet(Precision:=21, Scale:=0)> ByVal ID As Decimal)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top