microsoft / mssql-scripter

Repository for the new SQL cross-platform command line tools
Other
740 stars 148 forks source link

Parameter "--include-dependencies" is broken. #238

Open relatics-sdj opened 4 years ago

relatics-sdj commented 4 years ago

Hi all,

We can generate a SQL create script for a certain schema, however when we add the parameter "--include-dependencies" the script crashes.

Can someone help out? Thanks in advace!

You can find the stacktrace below:

Scripting request submitted with request id: 13ee27f4-1889-4f6d-91c4-df6743794f55 Scripting request: 13ee27f4-1889-4f6d-91c4-df6743794f55 encountered error: An error occurred while scripting the objects. Error details: Microsoft.SqlServer.Management.SqlScriptPublish.SqlScriptPublishException: An error occurred while scripting the objects. ---> Microsoft.SqlServer.Management.Smo.FailedOperationException: Discover dependencies failed. ---> System.ArgumentNullException: Value cannot be null. Parameter name: stream at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen) at Microsoft.SqlServer.Management.Smo.SqlEnumDependencies.EnumDependencies(Object ci, DependencyRequest rd) at Microsoft.SqlServer.Management.Smo.ExecutionManager.GetDependencies(DependencyRequest dependencyRequest) at Microsoft.SqlServer.Management.Smo.DependencyWalker.DiscoverDependencies(Urn[] urns, Boolean parents) --- End of inner exception stack trace --- at Microsoft.SqlServer.Management.Smo.DependencyWalker.DiscoverDependencies(Urn[] urns, Boolean parents) at Microsoft.SqlServer.Management.Smo.SmoDependencyDiscoverer.CallDependencyWalker(Urn[] urns) at Microsoft.SqlServer.Management.Smo.SmoDependencyDiscoverer.ReferenceDiscovery(HashSet1 urns) at Microsoft.SqlServer.Management.Smo.SmoDependencyDiscoverer.Discover(IEnumerable1 urns) at Microsoft.SqlServer.Management.Smo.ScriptMaker.Discover(IEnumerable1 urns) at Microsoft.SqlServer.Management.Smo.ScriptMaker.DiscoverOrderScript(IEnumerable1 urns) at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptWorker(List1 urns, ISmoScriptWriter writer) at Microsoft.SqlServer.Management.SqlScriptPublish.SqlScriptGenerator.DoScript(ScriptOutputOptions outputOptions) --- End of inner exception stack trace --- at Microsoft.SqlServer.Management.SqlScriptPublish.SqlScriptGenerator.DoScript(ScriptOutputOptions outputOptions) at Microsoft.SqlTools.ServiceLayer.Scripting.ScriptingScriptOperation.Execute() in D:\repos\sqltoolsservice\src\Microsoft.SqlTools.ServiceLayer\Scripting\ScriptingScriptOperation.cs:line 64`

nakanaa commented 3 years ago

I had the same error, but it seems that updating sqltoolsservice fixes this.

To be more precise, I:

  1. Downloaded alpha.72 release of sqltoolsservice from https://github.com/microsoft/sqltoolsservice/releases/tag/v1.5.0-alpha.72 (any newer and there seemed to be other problems) (in my case Microsoft.SqlTools.ServiceLayer-osx-x64-netcoreapp2.2.tar.gz)
  2. Extracted the files to {python-installation}/site-packages/mssqlscripter/mssqltoolsservice/bin overwriting all files (use pip show mssql-scripter to find the directory)
  3. Reverted the utf-16 => utf-8 change done here (not sure why it now needs to be utf-16 again, just got a 'utf-8' codec can't decode error and figured it's because of that line of code
  4. Done

EDIT: Here's the commands I use now on Docker to fix this:

curl -L https://github.com/microsoft/sqltoolsservice/releases/download/v1.5.0-alpha.73/Microsoft.SqlTools.ServiceLayer-rhel-x64-netcoreapp2.2.tar.gz --output /root/Microsoft.SqlTools.ServiceLayer-rhel-x64-netcoreapp2.2.tar.gz
tar -xf /root/Microsoft.SqlTools.ServiceLayer-rhel-x64-netcoreapp2.2.tar.gz -C /usr/local/lib/python3.7/site-packages/mssqlscripter/mssqltoolsservice/bin
rm /root/Microsoft.SqlTools.ServiceLayer-rhel-x64-netcoreapp2.2.tar.gz
sed -i 's/utf-8/utf-16/g' /usr/local/lib/python3.7/site-packages/mssqlscripter/main.py