Active Query Builder support area

How to load a saved xml with userqueries and favourites?

Avatar
  • updated
  • Answered

I have saved a XML file using  UserQueries.ExportToXML(...) and it looks good.
The file contains my favourites and the folders as well as the userqueries.
My problem is now to load it when opening a server connection.
I tried 
UserQueries.ImportFromXML(...)
QueryBuilder.MetadataStructure.ImportFromXML(...)


Using UserQueries.ImportFromXMl shows me the error 

"Exception: Incorrect xml schema: unexpected element "metadata_type" at line 15, pos 89" 


When using QueryBuilder.MetadataStructure.ExportFavouritesToXML and ImportFavouritesFromXML it works fine, except I get no userqueries.

I'm using AQB 3.9.2.2234  in VS2022 in a VB.Net Basic Winform.

I wanted to add my XML file, but I could not add it to this post


Avatar
werner brandenburg

Here is my XML (the 2 lines <user_data> are cut on the right)

Avatar
Andrey Zavyalov, PM

Hello Werner, 

Thank you for your question.

We will investigate this issue and let you know about result shortly.

Avatar
Andrey Zavyalov, PM

Hello Werner,

This bug is fixed in the new version 3.9.5.

Avatar
werner brandenburg

Hi Andrey,

thank you. Now the error has gone, but I'm still not able to load user queries.
I use UserQueries.ExportToXML(container,structure,file) and UserQueries.ImportFromXML(container,structure,file)
The favourites are loaded but no user query. The debugger shows me the user queries in the metadatacontainer along with the server databases (here item 13 is my user query, the others are SQL databases).
Did I miss something? Maybe some extra assignment/refreshing etc.? 

Avatar
Andrey Zavyalov, PM

Hello Werner,

seems you use the right methods, but not sure about your "container, structure, file" part.

Let me explain. If you turn "User Queries" pane on, there is additional UI tree control for user queries.
So there are two separate metadata structures: one for the main "database objects tree" (with favorites), and one for "user queries tree".

To save both "Favorites" and "User Queries" you should save both structures:

var ctx = queryBuilder1.SQLContext;
// save userqueries (the items itself) and their layout (the metadata structure)
UserQueries.ExportToXML(ctx.MetadataContainer, ctx.UserQueriesStructure, @"structure-uq.xml");
// save favorites (and possibly customized layout)
ctx.MetadataStructure.ExportToXML(@"structure-mc.xml");

To load saved structures back:

var ctx = queryBuilder1.SQLContext;
ctx.MetadataStructure.ImportFromXML(@"structure-mc.xml");
UserQueries.ImportFromXML(ctx.MetadataContainer, ctx.UserQueriesStructure, @"structure-uq.xml"); // initialize UI controls queryBuilder1.InitializeDatabaseSchemaTree();
Avatar
werner brandenburg

Hi Andrey,
thank you so much. Things could be so easy.
During my tests I was quite close to that (saving in 2 files), but I missed one important thing. 

That was the 

var ctx = querybuilder1.SQLcontext
   
Avatar
Andrey Zavyalov, PM
  • Answered