On Mon, Jul 16, 2012 at 12:37 PM, Grace Batumbya <
grace.batum...@senecacollege.ca> wrote:

> Hi there,
> With the shared-cache enabled, attaching a database to a second instance
> of the database connection throws an error : "database is already attached".
> Why does this happen? is it by design or is it a bug?
>

We would not have had an error message for this specific issue where it not
by design.  But that design happened so long ago, that I do not recall the
reason, right off hand, why the restriction is in place.

Why do you want to attach the same database twice?  What are you hoping to
accomplish?



>
> Here is how to replicate the error:
>
> #include <stdio.h>
> #include "sqlite3.h"
>
> int main(int argc, char **argv){
>   sqlite3 *dbCon1;
>   sqlite3 *dbCon2;
>   int rc = SQLITE_OK;
>   char *err;
>
>   sqlite3_enable_shared_cache(1); // enable shared cache
>   sqlite3_open("c:\\temp\\Database.sqlite", &dbCon1);
>   if((rc = sqlite3_exec(dbCon1, "attach 'c:\\temp\\Database.sqlite' as
> db;", 0, 0, &err)) != SQLITE_OK){
>     printf("Error attaching: %s\n", err)
>     sqlite3_close(dbCon1);
>     return rc;
>   }
>
>   sqlite3_open("c:\\temp\\Database.sqlite", &dbCon2);
>   if((rc = sqlite3_exec(dbCon2, "attach 'c:\\temp\\Database.sqlite' as
> db;", 0, 0, &err)) != SQLITE_OK){
>     printf("Error attaching: %s\n", err);
>     sqlite3_close(dbCon2);
>     return rc;
>   }
>
>   printf("attached on both connections\n");
>   sqlite3_close(dbCon1);
>   sqlite3_close(dbCon2);
> }
>
> Grace Batumbya
> Research Assistant | Seneca CDOT
> Phone: 416-491-5050 x3548
> cdot.senecac.on.ca<http://cdot.senecac.on.ca/>
>
>
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



-- 
D. Richard Hipp
d...@sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to