0

So I have an automation tool that uses c# to invoke a Powershell script that will use sqlpackage.exe to extract a database on a remote server into a .dacpac and save it into my file system.

We use asynchronous calls to the powershell process/pipeline to get the current result of the script execution and output them to the screen for the user. This tool has worked fine for ages but suddenly is stopping halfway through the extraction process and throwing the following error message "Error extracting database:Could not export schema and data from database.Can not access a closed Stream." At this point I have no idea what is causing the stream to get interupted and the extraction process to come to sudden halt.

Just wondering if anyone has experienced anything similar or if anyone can recommend some steps to debug this error?

Here is the portion of my script that is performing the extraction:

sqlpackage `
        /action:extract  `
        /SourceConnectionString:"$endpoint"  `
        /TargetFile:"$dacPacFile" `
        /p:ExtractAllTableData=True  `
        /p:ExtractReferencedServerScopedElements=False `
        /p:IgnoreUserLoginMappings=True 
Josh L
  • 1,412
  • 2
  • 18
  • 40
  • I googled the error, and [this](https://social.msdn.microsoft.com/Forums/sqlserver/en-US/4da7fd2a-6867-4dd4-945a-b277cb8d516f/dacservicesexportbacpac-fails-repeatedly-for-a-single-azure-database-exception-can-not-access-a?forum=ssdt) suggests it's caused by disk filling up. Could it be that? – TessellatingHeckler Oct 28 '16 at 18:07
  • Hmm seems the OP had the same problem as me but there was no resolution in his thread. I've made sure it was not a disc space issue and checked all directories mentioned – Josh L Oct 28 '16 at 18:22

2 Answers2

0

The "can not access a closed stream" error message can unfortunately obscure the actual issue. You can enable SqlPackage tracing, which will capture all errors to an ETL file that can be opened using the event viewer. The steps to gather an event log are:

  • Open a new command prompt as Administrator and run the following command: logman create trace -n DacFxDebug -p "Microsoft-SQLServerDataTools" 0x800 -o "%LOCALAPPDATA%\DacFxDebug.etl" -ets
  • Logging is now enabled, so retry the operation, reproducing the issue.
  • Disable logging by returning to the command prompt and running the following command: logman stop DacFxDebug -ets
  • The resulting ETL file will be located at %LOCALAPPDATA%\DacFxDebug.etl.
  • DacFxDebug.etl can be opened with Event Viewer's Open Saved Log... button
Steven Green
  • 3,387
  • 14
  • 17
-1

i believe it is due to update issue, me to facing similar issue

manoj
  • 104
  • 2