Search code examples
visual-studio-2013sql-server-data-toolsdatabase-projectdacpac

How I can Create log for post deployment script in dacpac?


I am using the SQL server Database Project. To deploy .dacpac file I am using the SqlPackage.exe with command line arguments.

Using Action: DriftReport, I am able to create the log (Added/update/Modified) of objects. But Still I am not able to create the log for post deployment script (operation like insert, update, etc).

Is there any way to create reports for successful and failures data insertion.


Solution

  • What I have done to achieve this is about same as Peter's comment. I got a batch file something as follow

    sqlpackage.exe /a:publish /tcs:"the connection string" /sf:".\package.dacpac"  >"%1" 2>"%2"
    FOR %%A IN ("%2") DO SET FileSize=%%~zA
    if %FileSize% gtr 0 start notepad "%2"
    

    Then I would run the batch as:

    thebatch.bat result.txt error_result.text
    

    The idea was redirect the output of this console command into file "result.txt"(by using " >") and redirect the error message to "error_result.text"(by using " 2>"), and then to rely on %~z in batch file to get a file size and open the file only if something went wrong.