Ask a questionAsk a question
 

AnswerRole membership is managed in the transacted part of the script

  • Friday, May 15, 2009 4:00 PMTheBeardedLlama Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello (again),

    Sick of me yet? ;P

    So, now it's time to start getting my other team mates to start using the database project.

    I just had a very interesting thing happen. The short story is that when the "Include transactional scripts" deployment setting is enabled and "Ignore role membership" is disabled, then GDR sticks the EXECUTE sp_addrolemember @rolename = N'xxx', @membername = N'yyy' statements in the transaction part of the script even though this cannot be done inside a transaction (as management studio says if you try to run the generated deployment script).

    Another bug?

    Cheers,
    Steven

Answers

  • Thursday, May 21, 2009 9:06 PMtomsmiMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Did some more investigating - are you by chance deploying to a SQL 2000 server?   Because a SQL 2000 server does get that error. 

    Thanks,
    -Tom

    Tom Smith, SDET - Microsoft Visual Studio Team Edition for Database Professionals
  • Friday, May 22, 2009 8:17 AMTheBeardedLlama Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Tom,
    No I wasn't, but I have a strong suspicion that it had to do with the compatibility level and your comments have confirmed this.
    Sorry about the false alarm, but just in case anybody else gets stuck:
    Make sure that when you generate a script for SQL Server 2005 you are not deploying to SQL Server 2005 with the compatibility level set to SQL Server 2000.

    Cheers,
    Steven

All Replies

  • Monday, May 18, 2009 8:36 PMtomsmiMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Steven,

    Based on my findings, it appears as though SQL server does allow role sp_addrolemember statements to be executed inside of a transaction.  What is the error you are getting when you try to deploy your script?  The error should be able to help me investigate further.

    Thanks!

    -Tom

    Tom Smith, SDET - Microsoft Visual Studio Team Edition for Database Professionals
  • Tuesday, May 19, 2009 8:36 AMTheBeardedLlama Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello Tom,

    The script was run on SQL Server 2005 Developer edition. The error said that the sproc to add a role member cannot be run inside a transaction.
    I just had a thought: would the compatibility level affect this behaviour?

    Cheers,
    Steven
  • Wednesday, May 20, 2009 12:53 AMtomsmiMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hmmm...What compat level is your database?   Can you by chance send the sample deploy script that is failing?  Maybe I'm misisng something and don't have a deploy setting that matches yours?

    Thanks!
    -Tom

    Tom Smith, SDET - Microsoft Visual Studio Team Edition for Database Professionals
  • Thursday, May 21, 2009 9:06 PMtomsmiMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Did some more investigating - are you by chance deploying to a SQL 2000 server?   Because a SQL 2000 server does get that error. 

    Thanks,
    -Tom

    Tom Smith, SDET - Microsoft Visual Studio Team Edition for Database Professionals
  • Friday, May 22, 2009 8:17 AMTheBeardedLlama Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Tom,
    No I wasn't, but I have a strong suspicion that it had to do with the compatibility level and your comments have confirmed this.
    Sorry about the false alarm, but just in case anybody else gets stuck:
    Make sure that when you generate a script for SQL Server 2005 you are not deploying to SQL Server 2005 with the compatibility level set to SQL Server 2000.

    Cheers,
    Steven
  • Wednesday, July 01, 2009 5:24 AMsnoopdiggy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Although this may be true for sp_addrolemember, it is NOT true for sp_droprolemember

    VSTS Database GDR will try to execute sp_droprolemember within the transaction and an error message is produced:

    "The procedure 'sys.sp_droprolemember' cannot be executed within a transaction."