Refreshing field information after database change

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
dupe
Posts: 20
Joined: Wed 15 Jun 2016 13:37

Refreshing field information after database change

Post by dupe » Fri 23 Sep 2016 10:53

In our application we are switching database connections during runtime.
Each database uses the same view but with different columns.
If we change the database from the connection during runtime the TMSQuery keeps all the field information of the old database.
This is a problem because every view in each database has additional or different field informations.

Code: Select all

connection.Database := 'Database1';
query.Connection := connection;
query.SQL.Text := 'SELECT * FROM View';
query.Open;
query.Close;
connection.Database := 'Database2';
query.Open; // <- Query has already fields of Database1 View
How do we refresh all the field informations?

Thanks in advance

paweld
Posts: 11
Joined: Mon 29 Sep 2014 08:56

Re: Refreshing field information after database change

Post by paweld » Sat 24 Sep 2016 17:41

Code: Select all

connection.Database := 'Database1';
query.Connection := connection;
query.SQL.Text := 'SELECT * FROM View';
query.Open;
query.Close;
connection.Database := 'Database2';
query.Fields.Clear;
query.Open; 

Post Reply