|
| 1 | +--- |
| 2 | +title: Troubleshooting Import/Export with SqlPackage |
| 3 | +description: Learn how to troubleshoot import and export with SqlPackage.exe. |
| 4 | +ms.prod: sql |
| 5 | +ms.prod_service: sql-tools |
| 6 | +ms.technology: tools-other |
| 7 | +ms.topic: conceptual |
| 8 | +ms.assetid: 198198e2-7cf4-4a21-bda4-51b36cb4284b |
| 9 | +author: "dzsquared" |
| 10 | +ms.author: "drskwier" |
| 11 | +ms.reviewer: "maghan; sstein" |
| 12 | +ms.date: 5/5/2021 |
| 13 | +--- |
| 14 | + |
| 15 | +# Troubleshooting Import/Export with SqlPackage |
| 16 | + |
| 17 | +In some scenarios, import or export operations take longer than expected or fail to complete. The following are some frequently suggested tactics to troubleshoot import and export operations. While reading the specific documentation page for each action to understand the available parameters and properties is recommended, this article serves as a starting point in investigating SqlPackage Import or Export operations. |
| 18 | + |
| 19 | +## Overall strategy |
| 20 | +As general guideline, better performance can be obtained via the [.NET Core version](sqlpackage-download.md#get-sqlpackage-net-core-for-windows) of SqlPackage.exe. |
| 21 | + |
| 22 | +1. [Download](sqlpackage-download.md#get-sqlpackage-net-core-for-windows) the zip for SqlPackage on .NET Core for your operating system (Windows, macOS, or Linux). |
| 23 | +2. Unzip archive as directed on the download page. |
| 24 | +3. Open a command prompt and change directory (`cd`) to the SqlPackage folder. |
| 25 | + |
| 26 | +For Import, an example command is: |
| 27 | +```bash |
| 28 | +./SqlPackage /Action:Import /sf:<source-bacpac-file-path> /tsn:<full-target-server-name> /tdn:<a new or empty database> /tu:<target-server-username> /tp:<target-server-password> /df:<log-file> |
| 29 | +``` |
| 30 | + |
| 31 | +For Export, an example command is: |
| 32 | +```bash |
| 33 | +./SqlPackage /Action:Export /tf:<target-bacpac-file-path> /ssn:<full-source-server-name> /sdn:<source-database-name> /su:<source-server-username> /sp:<source-server-password> /df:<log-file> |
| 34 | +``` |
| 35 | + |
| 36 | +Alternative to username and password, [Universal Authentication](/azure/azure-sql/database/authentication-mfa-ssms-overview) can be used to authenticate via Azure AD with MFA. Substitute the username and password parameters for `/ua:true` and `/tid:"yourdomain.onmicrosoft.com"`. |
| 37 | + |
| 38 | +For issues related to timeouts, the properties `CommandTimeout` and `LongRunningCommandTimeout` can be used to tune the connection between SqlPackage.exe and the SQL instance. |
| 39 | + |
| 40 | +## Diagnostics |
| 41 | +Logs are essential to troubleshooting. Capture the diagnostic logs to a file with the `/DiagnosticsFile:<filename>` parameter. |
| 42 | + |
| 43 | +Additional performance-related trace data can be logged by setting the environment variable `DACFX_PERF_TRACE=true` before running SqlPackage. To set this environment variable in PowerShell, use the following command: |
| 44 | +``` powershell |
| 45 | +Set-Item -Path Env:DACFX_PERF_TRACE -Value true |
| 46 | +``` |
| 47 | + |
| 48 | +## Import action tips |
| 49 | +For imports that contain large tables or tables with many indexes, the use of `/p:RebuildIndexesOfflineForDataPhase=True` or `/p:DisableIndexesForDataPhase=False` may improve performance. These properties modify the index rebuild operation to occur offline or not occur, respectively. Those and other properties are available to tune the [SqlPackage.exe Import](sqlpackage-import.md) operation. |
| 50 | + |
| 51 | +## Export action tips |
| 52 | +As an alternative operation to obtain the database schema and data while skipping the schema validation, perform an [Extract](sqlpackage-extract.md) with `/p:ExtractAllTableData=True` and `/p:VerifyExtraction=True`. |
| 53 | + |
| 54 | +In scenarios where disk space is limited and runs out during the export, the use of `/p:TempDirectoryForTableData` allows the data for export to be buffered on an alternative disk. That and other properties are available to tune the [SqlPackage.exe Export](sqlpackage-export.md) operation. |
| 55 | + |
| 56 | +## Next steps |
| 57 | + |
| 58 | +- Learn more about [SqlPackage Import](sqlpackage-import.md) |
| 59 | +- Learn more about [SqlPackage Export](sqlpackage-export.md) |
0 commit comments