Refreshing metadata after database connection changes with Query builder window active
I'm using version: 126.96.36.1990.
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:
SELECT mtech.ProteinCities.CityNo, mtech.ProteinCities.CityName
After (Changed the database of the connection string):
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();
queryBuilder.OfflineMode = true;
queryBuilder.OfflineMode = false;
July 26 2012, 06:04 PM
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.
4 days, 20 hours since original post