I'm hoping someone can help me with this as I am ripping my hair out.
I am creating an application that uses a SQL Server Compact to store a set of data. I am using TADOQuery to connect to the server which is working fine and I am able to create tables and insert values in to the database. I can then check this in Management Studio to ensure that everything was completed successfully which it is.
The problem I encounter is when I then try to retrieve the data from a table. In Management Studio I can execute a standard SQL Query
SELECT * FROM Components
This happily returns a table containing all the data stored in the components table.
However when I then execute this code in Delphi using a TADOQuery I get an "object was open" error. The code I am using is as follows.
Query := TADOQuery.Create(nil);
Query.ConnectionString := 'Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=c:\temp\test.sdf';
Query.SQL.Text := 'SELECT * FROM Components';
Query.Open;
This then leads to a "object was open" error.
Any thoughts would be greatly appreciated!
Cheers,
Aly
Update
I updated my code as follows but I still get the same error. Any ideas?
Query := TADOQuery.Create(nil);
Connection := TADOConnection.Create(nil);
Connection.ConnectionString := 'Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5; Data Source=c:\temp\test.sdf';
Connection.LoginPrompt := False;
Query.Connection := Connection;
DataSource := TDataSource.Create(nil);
Query.DataSource := DataSource;
Query.SQL.Text := 'SELECT * FROM Components';
Query.Open;