Search code examples
transactionslinked-serverfluent-migrator

How to create a linked server using FluentMigrator?


I tried to run a regular Sql script to create a linked server object in my production environment using Execute.Sql() method of FluentMigrator, but I get following errors from MS Sql Server:

The error was The procedure 'sys.sp_addlinkedserver' cannot be  executed within a transaction.  
The procedure 'sys.sp_addlinkedsrvlogin' cannot be executed within a transaction.

Is there any way to execute the script outside the opened transaction by FluentMigrator?

Thanks a lot.


Solution

  • I also run it outside the normal transaction, by decorating the attribute like this:

    [Migration(201604061643, TransactionBehavior.None)]
    

    This is a new feature in current release, described here: https://github.com/schambers/fluentmigrator/wiki/Transaction-modes-for-the-migration-runner