views:

44

answers:

1

Hi My service is deployed on a few IIS and they execute a considerable number of instances (100-200) of 3-4 different Stored procedures simultaneously. The SPs are executed Via "executescalar".

All SPs are returning different value types. I realized that the values have been replaced for SP calls that are made at same time. I am sure about this because I got invalid cast exception for all calls, and SP logging was correct.

Could somebody tell me what's gone wrong!!!

-Thanks

CREATE PROCEDURE [DBO].[SPO_DATABASESERVER_GET_CONTEXT_FROMNWACCOUNTID_1.0.5]
            @NwAccountId      BIGINT  = NULL,              
            @ActionFlag VARCHAR(20) = 'NONE'      
AS

BEGIN    
DECLARE @DBID BIGINT
DECLARE @ConnectionString VARCHAR(250)    

IF COALESCE(@NWACCOUNTID,'') != ''                                      
    BEGIN           
      SELECT @DBID = DATABASEID
      FROM   NWACCOUNTMASTER
      WHERE  NWACCOUNTMASTERID = @NWACCOUNTID                                     
    END

 IF (COALESCE(@DBID,'') = '')
    BEGIN 
        RAISERROR ('No DB is assigned for NwAccountId %I64d.',16,1,@NwAccountId)
        RETURN 
    END

  IF EXISTS (SELECT 'X'
         FROM   ACDATABASESERVER
         WHERE  DATABASEID = @DBID)
  BEGIN
      SELECT
           @ConnectionString = CONNECTIONSTRING
      FROM   ACDATABASESERVER
      WHERE  DATABASEID = @DBID
  END

  IF (COALESCE(@ConnectionString,'') = '')
  BEGIN 
        RAISERROR ('SP failed to fetch ConnectionString for NwAccountId %I64d.',16,1,@NwAccountId)
        RETURN 
  END

SELECT @ConnectionString AS CONNECTIONSTRING
END
+1  A: 

"invalid cast exception" is not a SQL error...

Do you have different web code that expects different return types for the same stored proc?

It's impossible for SQL to have mixed or changing different return datatypes if every IIS calls the same server/database/stored proc and the stored proc has the same outout signature. The only causes could be:

  • different databases
  • different SQL Servers
  • stored procedures have IF SELECT int, varchar... ELSE SELECT varchar, int...
  • dynamic SQL
gbn
Thanks, Invalid cast is not coming through SP, I got this exception in the code while implicitly casting the returned value from Executescalar method. There are no conditional branches. There is only select @param statement at the end. Which is of different type for diff SP. but in one of the executions I use following query - string.Format("select networkId from acgroup where groupId ={0}", p_nGroupId); followed by object nNetworkId = oSqlFramework.GetScalarData(sql);
Panks
There is your error then: don't use the same client code to issue the same SQL
gbn
could you elaborate a bit more. Which client code? to issue same SQL?
Panks
you mean oSqlFramework? this instance is created fresh for each sql call.
Panks