Fazer uma PerguntaFazer uma Pergunta
 

RespondidoRefactoring not working when deploying

  • sexta-feira, 26 de junho de 2009 15:29Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Hi All,

    I am having the same issue as in this thread.
    http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/c68362df-ed28-4942-9531-d3ddfc5c769a?prof=required

    I renamed a table in my schema through the refactoring interface. A refactorlog is created.

    But when I deploy nothing is renamed. All that happens is an additional table is added without any data.

    I have searched the documentation about refactoring but I can't find any documentation that clearly teaches me what steps to take to have the deploy process create the changes for me in such a manner that they are only applied if not done so already by keeping track of the refactorguids in the __RefactorLog table.

    Me and my team consider this one of the last hurdles to take before we can confidently start adopting db projects through out our organisation.

    Regards,

    Ed Tijgen

Respostas

  • quarta-feira, 1 de julho de 2009 7:45Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    HI All,

    Thanks so much for your time and efforts.

    I am not sure that anything changed wince a few minutes ago, so I (or someone else) might run into the same problem again sometime in the future.
    But somehow completely automagicly the refactoring is working.

    For now, especially seeing how much support you guys are giving the community, I am confident to start using db projects in our organization.

    Once again many thanks.

    Regards,

    Ed Tijgen

Todas as Respostas

  • sexta-feira, 26 de junho de 2009 22:14Gert DrapersMSFTMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Just checking, but your are deploying, using deploy, not using schema compare, correct?
    Which schema is the __RefactoringLog table created in?
    Can you post the content of the <projectname>.refactorlog file.

    GertD @ www.DBProj.com
  • sexta-feira, 26 de junho de 2009 22:47Gokhan CaglarMSFT, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Hi Ed, are you using the R2 version(9.1.40413.00), there has been some fixes in this area.  Also when you say deploy, you don't mean write updates in Schema Compare, right?  This only works for deploy that's in the build menu.
  • sábado, 27 de junho de 2009 4:57Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    YEs Gert, I am deploying (not using schema compare)

    The __RefactoringLog table is not created at all, I mentioned that table because I read somewhere that is supposed to happen.

    THe contents of the refactorlog is as follows:
    <?xml version="1.0" encoding="utf-8"?>
    <Operations>
      <Operation Name="Rename Refactor" Key="7a737e46-bb55-461b-bad2-30181a2f9ee1" ChangeDateTime="06/26/2009 14:41:11">
        <Property Name="ElementName" Value="[dbo].[Table_1]" />
        <Property Name="ElementType" Value="ISql100Table" />
        <Property Name="ParentElementName" Value="[dbo]" />
        <Property Name="ParentElementType" Value="ISql90Schema" />
        <Property Name="NewName" Value="[Table_11]" />
      </Operation>
    </Operations>

  • sábado, 27 de junho de 2009 4:59Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    I realized I was still using an older version of the GDR so I downloaded and installed the R2 just now. The installer interface told me that the GDR was about to be updated.

    But still no luck, and indeed I am using the deploy process ( not the schema compare ) I tried both right clicking the project in solution explorer and deploying from there and I tried deploying from the build menu. Both are yielding no luck.

    Regards,

    Ed Tijgen
  • segunda-feira, 29 de junho de 2009 16:14JoyceWang_MSFTMSFTMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Hi Ed,

    When you deploy, did you see any warning or error output? Could you share the deploy script under .\sql\debug\? In the deployment script, did you see the part to create Refactorlog table on your target database?

    Thanks,
    Joyce
  • terça-feira, 30 de junho de 2009 8:04Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Hello Joyce,

    The deploy output text shows no errors. Here is it:
    ------ Build started: Project: VSRefactoring, Configuration: Debug Any CPU ------
      VSRefactoring -> C:\_data\Projects\Testing\dbprojects\VSRefactoring\VSRefactoring\sql\debug\VSRefactoring.dbschema
    ------ Deploy started: Project: VSRefactoring, Configuration: Debug Any CPU ------
        Deployment script generated to:
    C:\_data\Projects\Testing\dbprojects\VSRefactoring\VSRefactoring\sql\debug\VSRefactoring.sql

    ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
    ========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========


    And there is no mention of the REfactorLog table in the deployment script. Here is it:

    /*
    Deployment script for SourceDB
    */

    GO
    SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;

    SET NUMERIC_ROUNDABORT OFF;


    GO
    :setvar DatabaseName "SourceDB"
    :setvar DefaultDataPath "E:\_data\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\"

    GO
    USE [master]

    GO
    :on error exit
    GO
    IF (DB_ID(N'$(DatabaseName)') IS NOT NULL
        AND DATABASEPROPERTYEX(N'$(DatabaseName)','Status') <> N'ONLINE')
    BEGIN
        RAISERROR(N'The state of the target database, %s, is not set to ONLINE. To deploy to this database, its state must be set to ONLINE.', 16, 127,N'$(DatabaseName)') WITH NOWAIT
        RETURN
    END

    GO

    IF NOT EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)')
    BEGIN
        RAISERROR(N'You cannot deploy this update script to target DIVERSITYMOBILE. The database for which this script was built, SourceDB, does not exist on this server.', 16, 127) WITH NOWAIT
        RETURN
    END

    GO

    IF (@@servername != 'DIVERSITYMOBILE')
    BEGIN
        RAISERROR(N'The server name in the build script %s does not match the name of the target server %s. Verify whether your database project settings are correct and whether your build script is up to date.', 16, 127,N'DIVERSITYMOBILE',@@servername) WITH NOWAIT
        RETURN
    END

    GO

    IF CAST(DATABASEPROPERTY(N'$(DatabaseName)','IsReadOnly') as bit) = 1
    BEGIN
        RAISERROR(N'You cannot deploy this update script because the database for which it was built, %s , is set to READ_ONLY.', 16, 127, N'$(DatabaseName)') WITH NOWAIT
        RETURN
    END

    GO
    USE [$(DatabaseName)]

    GO

    GO
    /*
     Pre-Deployment Script Template                           
    --------------------------------------------------------------------------------------
     This file contains SQL statements that will be executed before the build script.   
     Use SQLCMD syntax to include a file in the pre-deployment script.           
     Example:      :r .\myfile.sql                               
     Use SQLCMD syntax to reference a variable in the pre-deployment script.       
     Example:      :setvar TableName MyTable                           
                   SELECT * FROM [$(TableName)]                   
    --------------------------------------------------------------------------------------
    */

    GO

    GO

    GO
    /*
    Post-Deployment Script Template                           
    --------------------------------------------------------------------------------------
     This file contains SQL statements that will be appended to the build script.       
     Use SQLCMD syntax to include a file in the post-deployment script.           
     Example:      :r .\myfile.sql                               
     Use SQLCMD syntax to reference a variable in the post-deployment script.       
     Example:      :setvar TableName MyTable                           
                   SELECT * FROM [$(TableName)]                   
    --------------------------------------------------------------------------------------
    */

    GO
    -- Refactoring step to update target server with deployed transaction logs

    GO

    GO



    I am getting a bit nervous now.

    Regards,

    Ed Tijgen
  • terça-feira, 30 de junho de 2009 16:14JoyceWang_MSFTMSFTMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Hi Ed,

    According the deployment script you have here, essentially nothing is created or dropped in this deployment.  This means, your database project has the same schema with the target database you are deploying to. Have you tried to compare your database project with the target database? Did you see any difference on the tables in the schema comparison designer?

    After refactoring, did you deploy to the same target database? You said nothing is renamed but an additional table. So do you see both Table_1 and Table_11 in your target database?

    Thanks,
    Joyce
  • terça-feira, 30 de junho de 2009 16:28Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Hi Joyce,

    Indeed the db schema was similar to the db project schema.

    I have removed table_11 now in the hope that when I deploy table_1 gets renamed to table_11. But what happens is that a table "table_11" is added.

    Again no error in the deplay output:
    ------ Build started: Project: VSRefactoring, Configuration: Debug Any CPU ------
      VSRefactoring -> C:\_data\Projects\Testing\dbprojects\VSRefactoring\VSRefactoring\sql\debug\VSRefactoring.dbschema
    ------ Deploy started: Project: VSRefactoring, Configuration: Debug Any CPU ------
        Deployment script generated to:
    C:\_data\Projects\Testing\dbprojects\VSRefactoring\VSRefactoring\sql\debug\VSRefactoring.sql

        Creating dbo.Table_11...
    ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
    ========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========

    Please review the new sql script:
    /*
    Deployment script for SourceDB
    */

    GO
    SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;

    SET NUMERIC_ROUNDABORT OFF;


    GO
    :setvar DatabaseName "SourceDB"
    :setvar DefaultDataPath "E:\_data\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\"

    GO
    USE [master]

    GO
    :on error exit
    GO
    IF (DB_ID(N'$(DatabaseName)') IS NOT NULL
        AND DATABASEPROPERTYEX(N'$(DatabaseName)','Status') <> N'ONLINE')
    BEGIN
        RAISERROR(N'The state of the target database, %s, is not set to ONLINE. To deploy to this database, its state must be set to ONLINE.', 16, 127,N'$(DatabaseName)') WITH NOWAIT
        RETURN
    END

    GO

    IF NOT EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)')
    BEGIN
        RAISERROR(N'You cannot deploy this update script to target DIVERSITYMOBILE. The database for which this script was built, SourceDB, does not exist on this server.', 16, 127) WITH NOWAIT
        RETURN
    END

    GO

    IF (@@servername != 'DIVERSITYMOBILE')
    BEGIN
        RAISERROR(N'The server name in the build script %s does not match the name of the target server %s. Verify whether your database project settings are correct and whether your build script is up to date.', 16, 127,N'DIVERSITYMOBILE',@@servername) WITH NOWAIT
        RETURN
    END

    GO

    IF CAST(DATABASEPROPERTY(N'$(DatabaseName)','IsReadOnly') as bit) = 1
    BEGIN
        RAISERROR(N'You cannot deploy this update script because the database for which it was built, %s , is set to READ_ONLY.', 16, 127, N'$(DatabaseName)') WITH NOWAIT
        RETURN
    END

    GO
    USE [$(DatabaseName)]

    GO

    GO
    /*
     Pre-Deployment Script Template                           
    --------------------------------------------------------------------------------------
     This file contains SQL statements that will be executed before the build script.   
     Use SQLCMD syntax to include a file in the pre-deployment script.           
     Example:      :r .\myfile.sql                               
     Use SQLCMD syntax to reference a variable in the pre-deployment script.       
     Example:      :setvar TableName MyTable                           
                   SELECT * FROM [$(TableName)]                   
    --------------------------------------------------------------------------------------
    */

    GO

    GO
    PRINT N'Creating dbo.Table_11...';


    GO
    CREATE TABLE [dbo].[Table_11] (
        [FieldA] NCHAR (10) NULL
    );


    GO

    GO
    /*
    Post-Deployment Script Template                           
    --------------------------------------------------------------------------------------
     This file contains SQL statements that will be appended to the build script.       
     Use SQLCMD syntax to include a file in the post-deployment script.           
     Example:      :r .\myfile.sql                               
     Use SQLCMD syntax to reference a variable in the post-deployment script.       
     Example:      :setvar TableName MyTable                           
                   SELECT * FROM [$(TableName)]                   
    --------------------------------------------------------------------------------------
    */

    GO
    -- Refactoring step to update target server with deployed transaction logs

    GO

    GO


    Again no refactoring is taking place :-(

    Is there hope for me and my team?

    Regards,

    Ed Tijgen

  • terça-feira, 30 de junho de 2009 16:44Jamie Laflen MSFTMSFTMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Could you post your refactoring log file?  Also, if you select the refacoring log <projectName>.refactorlog and look in the properties window (hit F4 to open the properties window) what is the build action for the .refactorlog file?


    Jamie Laflen, Developer, Microsoft
  • terça-feira, 30 de junho de 2009 16:53JoyceWang_MSFTMSFTMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Ok, Ed, slow down... let's don't jump into the conclusion of having hope or no hope too quickly :-)

    Let us back up a little bit. Could you do me a favor to try your mini scenario from scratch? I am trying to get a repro of your problem, but I couldn't.

    Could you try the following:

    1. Create a brand new database project
    2. Add a table Table_1
    3. Save your project
    4. In properties page, go to 'Deploy' tab.  Set to generate the script and deploy to database. Set the connection string to your target database. Note to give it a new database name, so that it won't overwrite your existing database.
    5. Deploy  <-- check your target database, you should see the new table created.
    6. In your project, rename refactoring Table_1 to Table_11.
    7. Make sure there is a file <project name>.refactorlog added into your project.
    8. Save the project and deploy to the same databse in 5. <-- note you don't need to change any setting in the properties page.
    9. At this stage, you should see the same target database with ONLY Table_11 in it.  <-- if not, please share your deployment script with me.


    Ed, if you do not want to share stuffs in the forum, you can send me via email to ywang AT microsoft DOT com.

    Thanks,
    Joyce

  • terça-feira, 30 de junho de 2009 16:56Jamie Laflen MSFTMSFTMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Is it possible that your database project’s SQL version is different than the version of the target database?  There is a bug where refactoring does not work correctly if the versions are different. 

     

    For instance, I have a SQL2005 project with a table I renamed from Table1 to Table1p.  The refactor log file looks like this:

     

    <?xml version="1.0" encoding="utf-8"?>

    <Operations>

      <Operation Name="Rename Refactor" Key="4183e395-8f14-4c3d-957b-f805430b1b52" ChangeDateTime="06/30/2009 16:49:13">

        <Property Name="ElementName" Value="[dbo].[Table1]" />

        <Property Name="ElementType" Value="ISql90Table" />

        <Property Name="ParentElementName" Value="[dbo]" />

        <Property Name="ParentElementType" Value="ISql90Schema" />

        <Property Name="NewName" Value="[Table1p]" />

      </Operation>

    </Operations>

     

    I then deploy to a SQL2008 database and the table Table1p is created.  If I change the logfile to be:

     

    <?xml version="1.0" encoding="utf-8"?>

    <Operations>

      <Operation Name="Rename Refactor" Key="4183e395-8f14-4c3d-957b-f805430b1b52" ChangeDateTime="06/30/2009 16:49:13">

        <Property Name="ElementName" Value="[dbo].[Table1]" />

        <Property Name="ElementType" Value="ISql100Table" />

        <Property Name="ParentElementName" Value="[dbo]" />

        <Property Name="ParentElementType" Value="ISql90Schema" />

        <Property Name="NewName" Value="[Table1p]" />

      </Operation>

    </Operations>

     

    You will also need to clear the __RefactorLog table of the row pertinent to this operation if you have already had a failed deployment to that database.

     

    This bug has been fixed in the next version of Visual Studio.


    Jamie Laflen, Developer, Microsoft
  • terça-feira, 30 de junho de 2009 17:41Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Could you post your refactoring log file?  Also, if you select the refacoring log <projectName>.refactorlog and look in the properties window (hit F4 to open the properties window) what is the build action for the .refactorlog file?


    Jamie Laflen, Developer, Microsoft

    Hi Jamie,

    Here is the content of the refactoring log file:

    <?xml version="1.0" encoding="utf-8"?>
    <Operations>
      <Operation Name="Rename Refactor" Key="7a737e46-bb55-461b-bad2-30181a2f9ee1" ChangeDateTime="06/26/2009 14:41:11">
        <Property Name="ElementName" Value="[dbo].[Table_1]" />
        <Property Name="ElementType" Value="ISql100Table" />
        <Property Name="ParentElementName" Value="[dbo]" />
        <Property Name="ParentElementType" Value="ISql90Schema" />
        <Property Name="NewName" Value="[Table_11]" />
      </Operation>
    </Operations>

    The build action is (apparently by default) Deployment Extension Configuration.

    Regards,

    Ed Tijgen
  • terça-feira, 30 de junho de 2009 17:46Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Is it possible that your database project’s SQL version is different than the version of the target database?  There is a bug where refactoring does not work correctly if the versions are different. 

     

    For instance, I have a SQL2005 project with a table I renamed from Table1 to Table1p.  The refactor log file looks like this:

     

    <? xml version = "1.0 " encoding = "utf-8 "?>

    < Operations >

      < Operation Name = "Rename Refactor " Key = "4183e395-8f14-4c3d-957b-f805430b1b52 " ChangeDateTime = "06/30/2009 16:49:13 ">

        < Property Name = "ElementName " Value = "[dbo].[Table1] " />

        < Property Name = "ElementType " Value = "ISql90Table " />

        < Property Name = "ParentElementName " Value = "[dbo] " />

        < Property Name = "ParentElementType " Value = "ISql90Schema " />

        < Property Name = "NewName " Value = "[Table1p] " />

      </ Operation >

    </ Operations >

     

    I then deploy to a SQL2008 database and the table Table1p is created.  If I change the logfile to be:

     

    <? xml version = "1.0 " encoding = "utf-8 "?>

    < Operations >

      < Operation Name = "Rename Refactor " Key = "4183e395-8f14-4c3d-957b-f805430b1b52 " ChangeDateTime = "06/30/2009 16:49:13 ">

        < Property Name = "ElementName " Value = "[dbo].[Table1] " />

        < Property Name = "ElementType " Value = "ISql100Table " />

        < Property Name = "ParentElementName " Value = "[dbo] " />

        < Property Name = "ParentElementType " Value = "ISql90Schema " />

        < Property Name = "NewName " Value = "[Table1p] " />

      </ Operation >

    </ Operations >

     

    You will also need to clear the __RefactorLog table of the row pertinent to this operation if you have already had a failed deployment to that database.

     

    This bug has been fixed in the next version of Visual Studio.


    Jamie Laflen, Developer, Microsoft

    Hi Jamie,

    The db project type is sql server 2008 and the target database is also 2008. In my refactorlog ( as I posted earlier ) the elementtype is ISql100Table

    Regards,

    Ed Tijgen
  • terça-feira, 30 de junho de 2009 18:03Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     


    Hi All,

    my appologies for missing something important.

    The __Refactorlog table was created but it was put in the system tables folder. This is why i missed it. However the __RefactorLog table remains empty

    Regards,

    Ed Tijgen

  • terça-feira, 30 de junho de 2009 18:06Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Ok, Ed, slow down... let's don't jump into the conclusion of having hope or no hope too quickly :-)

    Let us back up a little bit. Could you do me a favor to try your mini scenario from scratch? I am trying to get a repro of your problem, but I couldn't.

    Could you try the following:

    1. Create a brand new database project
    2. Add a table Table_1
    3. Save your project
    4. In properties page, go to 'Deploy' tab.  Set to generate the script and deploy to database. Set the connection string to your target database. Note to give it a new database name, so that it won't overwrite your existing database.
    5. Deploy  <-- check your target database, you should see the new table created.
    6. In your project, rename refactoring Table_1 to Table_11.
    7. Make sure there is a file <project name>.refactorlog added into your project.
    8. Save the project and deploy to the same databse in 5. <-- note you don't need to change any setting in the properties page.
    9. At this stage, you should see the same target database with ONLY Table_11 in it.  <-- if not, please share your deployment script with me.


    Ed, if you do not want to share stuffs in the forum, you can send me via email to ywang AT microsoft DOT com.

    Thanks,
    Joyce


    Hi Joyce,

    I have followed your instructions to the letter.
    Still a table is added instead of being renamed.

    However I do see something new in the refactorlog:
    -- Refactoring step to update target server with deployed transaction logs
    CREATE TABLE  __RefactorLog (OperationKey UNIQUEIDENTIFIER NOT NULL PRIMARY KEY)
    GO
    sp_addextendedproperty N'microsoft_database_tools_support', N'refactoring log', N'schema', N'dbo', N'table', N'__RefactorLog'
    GO

    !UPDATE! I now beleive the bove statement was once executed in my other project aswell becuase there I find the __RefactorLog table aswell, the reason i missed it is it is in the system tables folder. However in both db project ( the initial, and this new one) the __Refactorlog table remains empty and nothing is refactored.

    Here is the complete log file:
    /*
    Deployment script for RefactorTry2
    */

    GO
    SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;

    SET NUMERIC_ROUNDABORT OFF;


    GO
    :setvar DatabaseName "RefactorTry2"
    :setvar DefaultDataPath "E:\_data\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\"

    GO
    USE [master]

    GO
    :on error exit
    GO
    IF (DB_ID(N'$(DatabaseName)') IS NOT NULL
        AND DATABASEPROPERTYEX(N'$(DatabaseName)','Status') <> N'ONLINE')
    BEGIN
        RAISERROR(N'The state of the target database, %s, is not set to ONLINE. To deploy to this database, its state must be set to ONLINE.', 16, 127,N'$(DatabaseName)') WITH NOWAIT
        RETURN
    END

    GO

    IF NOT EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)')
    BEGIN
        RAISERROR(N'You cannot deploy this update script to target DIVERSITYMOBILE. The database for which this script was built, RefactorTry2, does not exist on this server.', 16, 127) WITH NOWAIT
        RETURN
    END

    GO

    IF (@@servername != 'DIVERSITYMOBILE')
    BEGIN
        RAISERROR(N'The server name in the build script %s does not match the name of the target server %s. Verify whether your database project settings are correct and whether your build script is up to date.', 16, 127,N'DIVERSITYMOBILE',@@servername) WITH NOWAIT
        RETURN
    END

    GO

    IF CAST(DATABASEPROPERTY(N'$(DatabaseName)','IsReadOnly') as bit) = 1
    BEGIN
        RAISERROR(N'You cannot deploy this update script because the database for which it was built, %s , is set to READ_ONLY.', 16, 127, N'$(DatabaseName)') WITH NOWAIT
        RETURN
    END

    GO
    USE [$(DatabaseName)]

    GO

    GO
    /*
     Pre-Deployment Script Template                          
    --------------------------------------------------------------------------------------
     This file contains SQL statements that will be executed before the build script.  
     Use SQLCMD syntax to include a file in the pre-deployment script.          
     Example:      :r .\myfile.sql                              
     Use SQLCMD syntax to reference a variable in the pre-deployment script.      
     Example:      :setvar TableName MyTable                          
                   SELECT * FROM [$(TableName)]                  
    --------------------------------------------------------------------------------------
    */

    GO

    GO
    PRINT N'Creating dbo.Table_11...';


    GO
    CREATE TABLE [dbo].[Table_11] (
        [column_1] INT NOT NULL,
        [column_2] INT NULL
    );


    GO

    GO
    /*
    Post-Deployment Script Template                          
    --------------------------------------------------------------------------------------
     This file contains SQL statements that will be appended to the build script.      
     Use SQLCMD syntax to include a file in the post-deployment script.          
     Example:      :r .\myfile.sql                              
     Use SQLCMD syntax to reference a variable in the post-deployment script.      
     Example:      :setvar TableName MyTable                          
                   SELECT * FROM [$(TableName)]                  
    --------------------------------------------------------------------------------------
    */

    GO
    -- Refactoring step to update target server with deployed transaction logs
    CREATE TABLE  __RefactorLog (OperationKey UNIQUEIDENTIFIER NOT NULL PRIMARY KEY)
    GO
    sp_addextendedproperty N'microsoft_database_tools_support', N'refactoring log', N'schema', N'dbo', N'table', N'__RefactorLog'
    GO

    GO

    GO


    I hope this helps shining a light on this.

    Thanks in advance,

    Ed Tijgen

     

  • terça-feira, 30 de junho de 2009 18:57JoyceWang_MSFTMSFTMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Contém Código
    Ed,

    Is this the deploy script from the second time? I don't understand why it still has the following piece. Creating the __RefactorLog should be done in the first-time deployment (step 5).  Do you have 'Always re-create database' option checked in Database.sqldeployment?

    -- Refactoring step to update target server with deployed transaction logs
    CREATE TABLE  __RefactorLog (OperationKey UNIQUEIDENTIFIER NOT NULL PRIMARY KEY)
    GO
    sp_addextendedproperty N'microsoft_database_tools_support', N'refactoring log', N'schema', N'dbo', N'table', N'__RefactorLog'
    GO 
    
    The refactorlog you provided all seems OK. So I assume refactoring itself succeeded. Then in the next deploy, you should see in the deployment script something like below

    PRINT N'The following operation was generated from a refactoring log file 17165144-551c-47dc-8758-209c7595015e';
    
    PRINT N'Rename [dbo].[Table1] to Table11';
    
    GO
    EXECUTE sp_rename @objname = N'[dbo].[Table1]', @newname = N'Table11', @objtype = N'OBJECT';
    
    GO
    -- Refactoring step to update target server with deployed transaction logs
    INSERT INTO [dbo].[__RefactorLog] (OperationKey) values ('17165144-551c-47dc-8758-209c7595015e')
    
    GO
    
  • terça-feira, 30 de junho de 2009 21:01Jamie Laflen MSFTMSFTMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Hi Ed,

     

    A couple questions:

     

    ·         The version of GDR is:

    Microsoft Visual Studio Team System 2008 Database Edition GDR Version 9.1.40413.00

     

    ·         Are you saying that on the second deploy you see the creation of the __RefactorLog table but not any values inserted into it?

    ·         This is a brand new project against a new database (just confirming)?

    ·         You are using the same credentials to deploy both times?

     

    I have the GDR version mentioned above and I cannot reproduce exactly the same behavior you are seeing.  I am sure there is something simple I am missing that would enable me to repro the problem!


    Jamie Laflen, Developer, Microsoft
  • quarta-feira, 1 de julho de 2009 7:26Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Contém Código
    Ed,

    Is this the deploy script from the second time? I don't understand why it still has the following piece. Creating the __RefactorLog should be done in the first-time deployment (step 5).  Do you have 'Always re-create database' option checked in Database.sqldeployment?

    -- Refactoring step to update target server with deployed transaction logs
    
    CREATE TABLE __RefactorLog (OperationKey UNIQUEIDENTIFIER NOT NULL PRIMARY KEY )
    GO
    sp_addextendedproperty N'microsoft_database_tools_support' , N'refactoring log' , N'schema' , N'dbo' , N'table' , N'__RefactorLog'
    GO
    The refactorlog you provided all seems OK. So I assume refactoring itself succeeded. Then in the next deploy, you should see in the deployment script something like below

    PRINT N'The following operation was generated from a refactoring log file 17165144-551c-47dc-8758-209c7595015e';

    PRINT N'Rename [dbo].[Table1] to Table11';

    GO
    EXECUTE sp_rename @objname = N'[dbo].[Table1]', @newname = N'Table11', @objtype = N'OBJECT';

    GO
    -- Refactoring step to update target server with deployed transaction logs
    INSERT INTO [dbo].[__RefactorLog] (OperationKey) values ('17165144-551c-47dc-8758-209c7595015e')

    GO
    Hi Joyce,

    This is the script from the second time yes. And I do not have the "Always recreate database" option checked

    Regards,

    Ed Tijgen
  • quarta-feira, 1 de julho de 2009 7:41Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Hi Ed,

     

    A couple questions:

     

    ·          The version of GDR is:

    Microsoft Visual Studio Team System 2008 Database Edition GDR Version 9.1.40413.00

     

    ·          Are you saying that on the second deploy you see the creation of the __RefactorLog table but not any values inserted into it?

    ·          This is a brand new project against a new database (just confirming)?

    ·          You are using the same credentials to deploy both times?

     

    I have the GDR version mentioned above and I cannot reproduce exactly the same behavior you are seeing.  I am sure there is something simple I am missing that would enable me to repro the problem!


    Jamie Laflen, Developer, Microsoft

    Hi Jamie,

    I have GDR Version 9.1.40413.00.

    I am using a new db with a new db project.

    The __RefactorLog table is not created while I have no <dbproject>.refactorlog in my db project.

    Only table_11 is added (so now I have 2 tables. table_1 and table_11). So I remove table_11 again.

    Once I do a refactor action (and a <dbproject>.refactorlog is created) and I deploy the __RefactorLog table is created (it is a part of my sql deploy script) but is left empty. Once again the table_1 is not renamed but table_11 is added.

    If I deploy a 3rd time the creation of the __RefactorLog table is omited.

    Regards,

    Ed Tijgen



  • quarta-feira, 1 de julho de 2009 7:45Ed Tijgen Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    HI All,

    Thanks so much for your time and efforts.

    I am not sure that anything changed wince a few minutes ago, so I (or someone else) might run into the same problem again sometime in the future.
    But somehow completely automagicly the refactoring is working.

    For now, especially seeing how much support you guys are giving the community, I am confident to start using db projects in our organization.

    Once again many thanks.

    Regards,

    Ed Tijgen
  • quarta-feira, 1 de julho de 2009 15:53JoyceWang_MSFTMSFTMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Ed -  we are glad to know that the whole thing worked out for you :-)