HomeActive Query BuilderRefreshing metadata after database connection changes with Query builder window active

Refreshing metadata after database connection changes with Query builder window active


I'm using version: 1.15.8.330.
Before I open the query builder I prompt the user for database connection information and am able to load the metadata in the form loading event using the provider EventMetadataProvider. After it opens, I have an option to that allows the user to update the connection. I'm having issues with my SQL statement updating as follows:

Before:
SELECT mtech.ProteinCities.CityNo, mtech.ProteinCities.CityName
FROM mtech.ProteinCities

After (Changed the database of the connection string):
SELECT Agrobueyca_v718_0626_20120711.mtech.ProteinCities.CityNo,
Agrobueyca_v718_0626_20120711.mtech.ProteinCities.CityName
FROM mtech.ProteinCities

I have tried clearing the metadata container and refreshing metadata as shown below but both don't seem to resolve the problem.
SqlConnection sqlConnection = new SqlConnection(_connectionInfo.QBConnectionString);
dbConnection = sqlConnection;
queryBuilder.MetadataProvider = new EventMetadataProvider();
((EventMetadataProvider)queryBuilder.MetadataProvider).ExecSQL += new ActiveDatabaseSoftware.ActiveQueryBuilder.ExecSQLEventHandler(this.EventMetadataProvider_ExecSQL);
queryBuilder.SyntaxProvider = new MSSQLSyntaxProvider();
dbConnection.Close();
dbConnection.Open();
queryBuilder.OfflineMode = true;
queryBuilder.MetadataContainer.Clear();
queryBuilder.OfflineMode = false;
queryBuilder.RefreshMetadata();


Please help.
Bob Onyango | email
July 26 2012, 06:04 PM
Dear Bob,

Seems that after changing the connection, the "Agrobueyca_v718_0626_20120711" database is no longer the default database, thus the component adds the database name to the table name. There are two ways to cope with this: you may save the SQL query text before changing the connection and restore it after that. Doing this you should understand that the query may become invalid in the context of a new database, so do this only if you sure that the new database schema is identical to the previous one. Second, you may change the default database. The default database name is stored in the QueryBuilder.MetadataContainer.DefaultDatabaseName property.
Sergey Smagin | email
4 days, 20 hours since original post
This topic is closed