1

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;
AlyD
  • 11
  • 3
  • 1
    Use a single `TADOConnection` and assign it to the `Connection` property of your queries. See DB_E_OBJECTOPEN [here](http://msdn.microsoft.com/en-us/library/ms718095%28VS.85%29.aspx). – Sertac Akyuz Jul 15 '12 at 22:59
  • Thanks, I updated the code as you suggested but I still get the same problem. I also read the link you provided but to be honest I'm not sure what to do with the information in terms of changing my code appropriately? – AlyD Jul 16 '12 at 09:48
  • What I meant was to use a single connection throughout the application, or something to that effect. I pointed out the documentation that explains why oledb throws the error you see, whether it helps you or not is beyond me. – Sertac Akyuz Jul 16 '12 at 10:05
  • Thanks, I was using a single connection to the database then I just made that very simple code for testing. And even with this get the "object was open" error. I'll need to keep looking, see if there is something stupid in my code. Thanks again for your help! – AlyD Jul 16 '12 at 11:10
  • @AlyD, check out my answer here: http://stackoverflow.com/a/14222561/800214 – whosrdaddy May 24 '13 at 17:24
  • @whosrdaddy thanks, I managed to find the 127 limitation after many a google search and found someone mention it in some ancient mailing list archive. Bit of a ridiculous limitation if you ask me but such is the way of things! I should have updated my post so others could find this answer too. – AlyD Jun 25 '13 at 13:42

0 Answers0