I recently got notified that my tool SMOscript raises an error message when run on Windows 10.
I had a look at the problem, and indeed, as soon as the enumeration of database objects (e.g. using commands l (list) or s (script)) is to process a table, the program stop. In case of the script command, an error message is issued
Error: iterating objects: Attempt to retrieve data for object failed for Server ”.
The most recent version of SMOscript was still targeted on .Net 2.0, and used the SMO 100 assemblies. Time to upgrade! 😉
So I changed the .Net version to 4.5 and added the nuget SMO package and changed the .Net version to 4.7 to make the compiler happy.
Tests were performed successfully against SQL Server 2014 and 2019, but now SQL Server 2008 caused an error that I could work-around.
The tool now also supports options to sort database objects by schema and name, or by type and schema and name, rather than relying on the order resulting from the SMO method Database.EnumObjects().
Additionally, the -st (Sort Types) parameter allows to specify a custom sort order for database object types (rather than alphabetically), so that the parameter
smoscript -st Table,View
will process objects of types table and view first, and everything else afterwards. The parameter -st without a list of types will display the available types.
The latest version of SMOscript is available for download here.
Note that there is a regular build “V 0.40”, but also a build using the original SMO 100 assemblies.