unhandled exception

Jul 5, 2011 at 12:41 AM

I use the tool to connect to SQL 2008R2 instance trying to gen one database, and I get the error

D:\>ExportSQLScript.exe .\sql2k8r2 dbname /ot:Files /of:CreationOrder.txt /od:"outdir" /ssq

Unhandled Exception: Microsoft.SqlServer.Management.Smo.FailedOperationException
: Attempt to retrieve data for object failed for Server 'SHIYANG-LAPTOP\sql2k8r2
'.  ---> System.ArgumentException: Invalid path: There is no collection of Unres
olvedEntity objects that is a child of Database.
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.GetChildCollection(SqlSmoO
bject parent, String childUrnSuffix, String categorystr, ServerVersion srvVer)
   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 ExportSQLScript.Program.ScriptDependencyTreeNode(DependencyTreeNode depend
   at ExportSQLScript.Program.ScriptDependencyTreeNode(DependencyTreeNode depend
   at ExportSQLScript.Program.Run()
   at ExportSQLScript.Program.Main()


what should i do?

Jul 5, 2011 at 4:19 AM

Hmm.... that's interesting. I have no idea what that error is about, and can't find any reference to it online.

Do you have any "interesting" objects in your database?

Unfortunately (without a debugger), there's not a good way to work out what's going on.

Jul 5, 2011 at 7:05 AM

i try some databases, all fail. now i'm downloading vs2010 and your source code to debug.

Jul 5, 2011 at 8:13 AM


i do the testing below and can repo the error:

0. create db testing

1. create table table_1

2. create stored proc up_sp1, select * from table_1

3. alter stored proc up_sp1, select * from table_2, which doesnt exist

4. use ExportSQLScript.exe to gen db testing.


My suggestion is to check if all the dependency object exist before generating the script, or provide an option to ignore dependency.

Jul 6, 2011 at 3:07 AM

I digged into the source code, and below is what i found

 List<DtnSmo> Children = new List<DtnSmo>();
                    DependencyTreeNode dependencyTreeNodeChild = dependencyTreeNode.FirstChild; //the child node may not exist
                    while (dependencyTreeNodeChild != null)
                        //should check if the child node exists here, if it doesn't exist, write down the info to error log and check next child node
                       // if the child node exists, exec the below steps.
                        DtnSmo sortUnit = new DtnSmo();
                        sortUnit.dependencyTreeNode = dependencyTreeNodeChild;
                        sortUnit.namedSmoObject = (NamedSmoObject)server.GetSmoObject(dependencyTreeNodeChild.Urn);
                        dependencyTreeNodeChild = dependencyTreeNodeChild.NextSibling;



Best regards,

Aug 24, 2011 at 7:14 AM

I uploaded a patch to the issue tracker. Please try that and see if it works for you. The patch adds a command line option to skip checking for dependencies.