microsoft / mssql-scripter

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

Error when database name ends in literal space character #199

Open daveloyall opened 5 years ago

daveloyall commented 5 years ago

We have a legacy database that has a literal space character ( ) as the last letter in the database name.

Please add this scenario to your test cases.

I apologize. This was probably caused by a typo. Now, we're stuck with it.

daveloyall commented 5 years ago

The problem might not be because of the space character. One of our other databases has the same thing, but the tool works against it.

Here is the lightly de-identified output of an attempt to run the tool against the db that fails. Could this be a permissions issue? Something related to schemas?

david.loyall@workstation MINGW64 /d/projects/supersecret/20180716-db-compare
$ mssql-scripter -S somedb1,1435 -d 'supsec_staging '
Scripting request: 058ae640-7704-442a-9449-02217d607356 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: Attempt to retrieve data for object failed for Server 'somedb1,1435'.  ---> Microsoft.SqlServer.Management.Smo.MissingObjectException: The Table '[dbo].[codeXref]' does not exist on the server.
   at Microsoft.SqlServer.Management.Smo.Server.GetSmoObjectRec(Urn urn)
   at Microsoft.SqlServer.Management.Smo.Server.GetSmoObject(Urn urn)
   --- End of inner exception stack trace ---
   at Microsoft.SqlServer.Management.Smo.Server.GetSmoObject(Urn urn)
   at Microsoft.SqlServer.Management.Smo.SmoDependencyDiscoverer.SfcChildrenDiscovery(HashSet`1 discoveredUrns)
   at Microsoft.SqlServer.Management.Smo.SmoDependencyDiscoverer.Discover(IEnumerable`1 urns)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.Discover(IEnumerable`1 urns)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.DiscoverOrderScript(IEnumerable`1 urns)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptWorker(List`1 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
albertosilva commented 2 years ago

We have a legacy database that has a literal space character ( ) as the last letter in the database name.

Please add this scenario to your test cases.

I apologize. This was probably caused by a typo. Now, we're stuck with it.

I was also getting the "MissingObjectException" error and after reading your post, I went to my SQL Server instance and realized that there was in fact a blank space at the end of the database name. Removing it fixed the error.

Two observations: