Question

I need to update dataset table adapter in Visual Studio 2010. It is based on a stored procedure. The store procedure has parameters

    @IDportfolio INT
,   @Date varchar(50)           = NULL
,   @IDorder int                = NULL
,   @IDsession nvarchar(300)    = NULL
,   @User varchar(100)          = NULL
,   @UDNsXML NVARCHAR(MAX)      = NULL
,   @DEBUG  INT                 = 0

The table adapter had this methods:

Fill,GetData (@IDportfolio, @Date, @IDorder, @IDsession, @User, @UDN)

So I needed to refresh it. In the procedure there is one IF statement that gets executed only if @DEBUG is set to 1. Inside this IF statement there are some SELECT statements used for internal debugging. Value 1 is obviously not default value as can be seen in the signature, yet designer, when refreshing the methods, acts like it is sending value 1 for @DEBUG parameter. So instead of returning values that should be returned, it returns wrong set of values, and designer tries to make methods based on these returned values.

Why is designer working like that and is there some default value for INT parameters, or is he ignoring default values? I have noticed similar behavior in Entity Framework too.

Was it helpful?

Solution

OK well the (VS) designer needs to determine the sent values (parameters) and the returned values (columns and data types). (to generate associated classes). It uses what could loosely be called reflection. To do this the stored procedure must conform to certain rules, there are 4 i've discovered, off the top of my head, here are the important 3:

  • Only one row set can be returned (this is explicitly stated by MS somewhere)
  • The row set must be persistent outside the stored procedure i.e. it cant come from a table variable. (this is explicitly stated by MS somewhere)
  • It must be deterministic. (this is explicitly stated by MS somewhere)

Using a debug parameter, which the calling softwaer will never set to 1 will allow you to run the proc for testing and return various value at different points in the stored procedure. However for the VS designer, because these rows are not (by defualt) returned, the proc will still behave when analysed by VS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top