Managment Studio. Different PC's give different result for same query.

  • Hi All,

    I have a problem that seems to be in the configuration of the PC's that we have running Management Studio.

    It seems that not all of them process the SQL in a query the same way.

    As an example I have a query that essentially does the following.

    IF

    Table T contains Field F

    THEN

    Update Table T

    Set Field F = 'Some Changes'

    ELSE

    print 'Field F does not exist. No changes made.'

    Table T does not contain Field F.

    On some of the PC's the query completes and prints that Field F does not exist as I would expect but on some others it fails and returns the error

    Msg 207, Level 16, State 1, Line 22

    Invalid column name 'Field F'.

    What is the option that is causing this difference in behaviour and how do I adjust it?

    Thanks for any help you can provide.

    Scott

  • I have never seen such thing in T-SQL before.

    Are you sure it's running properly on one of your PCs?

    Best regards,

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA

  • Sorry about that Andre, I guess that I wasn't really clear. The code example is just psudo-code for what the query does, it isn't the actual SQL that is run.

    The issue isn't really the code more that it seems to be pre-parsed and fail to run on some machines and not on others.

    Thanks for taking the time to look.

    Scott

  • Can you please post the actual query, DDL and sample data?

    Converting oxygen into carbon dioxide, since 1955.
  • I see. πŸ™‚

    It'd be nice to see the actual code though to see if there's a problem with different database compatibility levels.

    Best regards,

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA

  • OK I've included the SQL below but just to clarify I don't think that SQL is the problem, rather it is an issue with the configuration of Management Studio on the different PC's.

    On each PC I connect to the same server open the same file and execute, in all cases the column TFN_ENCRYPT does not exist.

    On some PC's the query completes and prints

    Either column [TFN] or [TFN_ENCRYPT] does not exist. No action taken

    On others it does not run and returns the error

    Msg 207, Level 16, State 1, Line 22

    Invalid column name 'TFN_ENCRYPT'.

    It seems on some of the PC's it pre-validates all the SQL statement and stops due to TFN_ENCRYPT not being a valid column name before it even runs the query. On the other PC's it processes the query and doesn't error on the TFN_ENCRYPT column as it never tries to execute that section, instead it prints the message in the else section.

    Hope that makes sense.

    Scott

    use [vsSit]

    go

    set ansi_nulls on

    go

    OPEN SYMMETRIC KEY vTfnKey DECRYPTION BY CERTIFICATE vsEncryptionCert

    go

    If exists (

    select *

    from [sys].[tables] a

    ,[sys].[columns] b

    where [a].[object_id] = object_id(N'[plasup].[MEMBER_T]')

    and [a].[name] = N'MEMBER_T'

    and .[object_id] = [a].[object_id]

    and .[name] = 'TFN_ENCRYPT'

    ) and exists (

    select *

    from [sys].[tables] a

    ,[sys].[columns] b

    where [a].[object_id] = object_id(N'[plasup].[MEMBER_T]')

    and [a].[name] = N'MEMBER_T'

    and .[object_id] = [a].[object_id]

    and .[name] = 'TFN'

    )

    begin

    update [plasup].[MEMBER_T]

    set TFN_ENCRYPT = ENCRYPTBYKEY(KEY_GUID('vTfnKey'),CONVERT(VARCHAR(11),TFN))

    end

    else

    begin

    print 'Either column [TFN] or [TFN_ENCRYPT] does not exist. No action taken'

    end

    go

    CLOSE SYMMETRIC KEY vTfnKey

  • This seems to be a parsing error and I don't think it has to do with SSMS as it's just a GUI (frontend) and it doesn't have control over query parsing errors.

    I'd ask you the questions below:

    1) Are both PC's executing the same SQL Server version (with equivalent service packs)? Sometimes a service pack introduces a new feature or changes an existing feature.

    2) Are both databases set to the same compatibility level?

    Best regards,

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA

  • Andre, both PC's are connecting to the same database on the server and as far as I know they are both running the same version of Management Studio.

  • Scott Levy (10/20/2011)


    Andre, both PC's are connecting to the same database on the server and as far as I know they are both running the same version of Management Studio.

    Sorry but without enough information about the SQL Server versions, editions, if both PC's are connecting to the same database on the same server or each one is a server on its own, if the database compatibility level is the same for both PC's and other information that could give us some hints we'd just be shooting in the dark here. πŸ™‚

    More technical information about your PC's setup would make things clearer.

    Best regards,

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA

  • Scott Levy (10/20/2011)


    Andre, both PC's are connecting to the same database on the server and as far as I know they are both running the same version of Management Studio.

    Are they both running at the same service pack level, etc? And are you absolutely sure that both are pointed to the same server AND database? I know... stupid questions. But I have to ask because I've seen this type of thing be overlooked before. πŸ˜‰

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • OK, thanks to everyone for your interest in this.

    I'll collect the details on a sample of the PC's around here as there is a bit of a mix of OS's as we are testing Win7.

    They are all defiantly pointing to the same DB on the same server though.

  • I'm going to have to admit a mea culpa here as returning to the other PC I can't get it to behave any differently than mine.

    In my defence it also has the owner of that PC stumped, he witnessed the inconsistent behaviour as well, we must have both missed something, or we are both delusional. πŸ™‚

    On a positive note I have worked out how to work around my issue by using dynamic SQL and storing the update code in a string before executing it.

    Once again thanks to those who took the time to ponder my problem, it was very much appreciated.

    Scott

  • Just a last update on this if anyone is interested as I think I may have found the source of the inconsistency.

    I believe that it was the local intellisense cache of the DB schema that management studio holds. I have been having issues with it flagging tables and fields as invalid when they are definitely there, a force refresh of the local cache and the issue goes away.

    Scott

  • Scott Levy (11/9/2011)


    Just a last update on this if anyone is interested as I think I may have found the source of the inconsistency.

    I believe that it was the local intellisense cache of the DB schema that management studio holds. I have been having issues with it flagging tables and fields as invalid when they are definitely there, a force refresh of the local cache and the issue goes away.

    Scott

    I am not convinced. Intellisense helps developers to write SQL code in SSMS with ease. It’s IDE feature. It should not affect your query results.

  • Dev @ +91 973 913 6683 (11/9/2011)


    I am not convinced. Intellisense helps developers to write SQL code in SSMS with ease. It’s IDE feature. It should not affect your query results.

    I was able to reproduce the behaviour where intellisense would be outdated and sometimes would show syntax errors while editing the code.

    But it would execute the commands with no erros as that issue doesn't affect the SQL parser. I can't see how a intellisense bug could influentiate the parser's behaviour.

    Best regards,

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA

Viewing 15 posts - 1 through 15 (of 20 total)

You must be logged in to reply to this topic. Login to reply