1

I have more than 400 sqlite databases. I need to query on these databases. Like simple SELECT..... query to get results.

I don't know weather it is possible within single query.

Current logic is.

foreach(FileInfo finf in Files)
{
    // query one database get result 
    Datatable results = execute();
    // merge Datatable with new one.
}

at the end we get all database results in single datatable.

Is anyone having better solution for querying multiple databases?

Thanks in advance.

2
  • 1
    yes i tried but maximum results are related to attach database. Which is inconvenience to me. It is same as current logic Commented Jan 17, 2014 at 7:18
  • your solution is not bad, but close unused SqLiteConnection(s) Commented Jan 17, 2014 at 21:21

1 Answer 1

1

In order to get a single result set with SQLite you have to join all the databases by the ATTACH command giving to each one a different alias, then build a sql statement which group the data into a single result set by the SELECT ... UNION command.

For example:

 - ATTACH DATABASE 'Database1' As 'DB1';
 - ATTACH DATABASE 'Database2' As 'DB2';

Then :

SELECT * FROM DB1.MyTable

UNION

SELECT * FROM DB2.MyTable
Sign up to request clarification or add additional context in comments.

2 Comments

I have more than 400 database. max limit of sqlite attach database is 62. sqlite.org/limits.html
Query by group og 62 queries and merge the results into DataTable object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.