开发者

stored procedure executes correctly from management studio, but not in production

I have a stored procedure that works correctly when I execute the stored procedure from SQL Server Management Studio. Unfortunately, it doesn't behave the the same way on the production server. On an insert statement, it is only inserting some of the values and the rest are NULL. The NULL values are comin开发者_开发知识库g from user defined scalar function calls (which also work correctly when executed from Management Studio). Has anyone run into anything similar? I was thinking it might be a permissions issue, but I connected to the database through Management Studio with the production connection credentials and saw the same behavior. I'm a C# developer that normally works with ORMs, so I'm definitely no SQL expert. Thanks in advance, guys.

Here is the code:

BEGIN 
    DECLARE @UserExists int 
    SET @UserExists = 0
    SELECT @UserExists = COUNT(*) FROM UserPass WHERE UserId = @UserID AND PortalID = @PORTALID


    --If the Action is add and a User Exists change the Action to EDT (Update)
    IF @Action = 'ADD' AND @UserExists > 0 
     SET @Action = 'EDT'

    --Get All Of the Properties for this User
    DECLARE @EMAIL nvarchar(255)
    DECLARE @FIRSTNAME nvarchar(50) 
    DECLARE @LASTNAME nvarchar(50) 
    DECLARE @GENDER char(1) 
    DECLARE @BIRTHDATE smalldatetime 
    DECLARE @ADDRESS nvarchar(50)
    DECLARE @CITY nvarchar(50) 
    DECLARE @STATE nchar(2) 
    DECLARE @COUNTRY nvarchar(50) 
    DECLARE @POSTALCODE nvarchar(10) 
    DECLARE @TELEPHONE nvarchar(20) 
    DECLARE @CELL nvarchar(20) 
    DECLARE @EMAILPERMISSION bit 
    DECLARE @TEXTPERMISSION bit 
    DECLARE @UPDATEDIRECTION nvarchar(3)

    BEGIN TRY
      SELECT @BIRTHDATE = CAST(dbo.GetPropertyValue(@PORTALID,@USERID,'Birthdate') AS SmallDatetime)

    END TRY
    BEGIN CATCH
      SELECT  @BIRTHDATE = NULL
    END CATCH

    SELECT @EMAIL = Email,
        @FIRSTNAME = dbo.Proper(Firstname), 
        @LASTNAME = dbo.Proper(Lastname),
        @GENDER = dbo.GetPropertyValue(@PORTALID,@USERID,'Gender'),
        @ADDRESS = dbo.GetPropertyValue(@PORTALID,@USERID,'Street'), 
        @CITY = dbo.Proper(dbo.GetPropertyValue(@PORTALID,@USERID,'City')), 
        @STATE = Upper(dbo.GetState(dbo.GetPropertyValue(@PORTALID,@USERID,'Region'))), 
        @COUNTRY = dbo.GetPropertyValue(@PORTALID,@USERID,'Country'), 
        @POSTALCODE = dbo.GetPropertyValue(@PORTALID,@USERID,'Postalcode'), 
        @TELEPHONE = dbo.STRFILTER(dbo.GetPropertyValue(@PORTALID,@USERID,'Telephone'),'0,1,2,3,4,5,6,7,8,9'), 
        @CELL = dbo.STRFILTER(dbo.GetPropertyValue(@PORTALID,@USERID,'Cell'),'0,1,2,3,4,5,6,7,8,9'), 
        @EMAILPERMISSION = dbo.GetPropertyValue(@PORTALID,@USERID,'eNewsLetter'), 
        @TEXTPERMISSION = dbo.GetPropertyValue(@PORTALID,@USERID,'TextPermission') 
    FROM Users 
    WHERE UserId = @USERID 


        -- Insert new user
        IF @Action = 'ADD'
            BEGIN

                INSERT INTO UserPass
                  (UserID, Portalid, CreatedDate, Username, UserPass.Password, email, firstname, lastname, gender, birthdate, UserPass.address, city, UserPass.state, country, postalcode, telephone, cell, emailpermission, textpermission, UpdateDirection)
                VALUES 
                  (@UserID, @PORTALID, @CREATEDDATE, @Username, @Password, @EMAIL, @FIRSTNAME, @LASTNAME,@GENDER, @BIRTHDATE, @ADDRESS, @CITY, @STATE, @COUNTRY, @POSTALCODE, @TELEPHONE, @CELL, @EMAILPERMISSION, @TEXTPERMISSION, 'OUT')

    END

@PORTALID and @USERID are passed to the stored procedure as parameters, and those values are actually saving in the insert. The columns that aren't updating are the ones that call the GetPropertyValue function for the value. This is only on one database server (I am not connecting to a dev database through Management studio, I am connecting directly to the production database). When I execute the stored procedure from Management Studio, it's perfect. When the trigger on the table calls the sproc, the GetPropertyValue function fails.


Get SQL Profiler on it and then copy & paste & execute the statements from that in query analyser.

It's likely that your production is producing subtlely different code or is injecting different param values than the ones you expect and this will catch exactly what is happening.


While it's impossible to see what is happening without table structures, sprocs and functions my thoughts would be to compare the table structures, defaults, identity columns, etc. in PROD and DEV.


That says to me something is funny in your application code. I would check your C# logic and make sure you are using the right function call on the command object. It might help to post your code.


As Nissan Fan says, you haven't provided nearly enough information. That said, one possibility is that you're on SQL Server 2000 and are encountering an old bug. If you want a useful answer, though, ask a useful question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜