[prev in list] [next in list] [prev in thread] [next in thread]
List: sqlite-users
Subject: [sqlite] SQLite creating disk file for memory db
From: Abhishek <abhishek.ginani () teramatrix ! co>
Date: 2018-05-27 18:12:07
Message-ID: 1527444727265-0.post () n5 ! nabble ! com
[Download RAW message or body]
I tried to create a shareable in-memory database as per the documentation
provided on SQLite Site. But I end up finding the solution to the problem.
*Here is my code in C#*:
var connectionString = "Data Source=sharedmemdb;Mode=Memory;Cache=Shared";
using (var connection1 = new SQLiteConnection(connectionString))
{
connection1.Open();
var command1 = connection1.CreateCommand();
command1.CommandText =
"CREATE TABLE Message ( Text TEXT );" +
"INSERT INTO Message ( Text ) VALUES ( 'Is there anybody
out there?' );";
command1.ExecuteNonQuery();
using (var connection2 = new
SQLiteConnection(connectionString))
{
connection2.Open();
var command2 = connection2.CreateCommand();
command2.CommandText = "SELECT Text FROM Message;";
var message = command2.ExecuteScalar() as string;
}
}
If I execute this code, it will create in-memory DB named as **sharedmemdb**
and shared cache is enabled while making the connection, so this connection
accessible to other connections also. If I run this first time this works
pretty fine but if I close the application and run again it throws error
"Table Message already exists" and this looks very strange as I created the
table in-memory and this should not be available if application restarts.
After getting this error, I looked into the application directory and found
the file "sharedmemdb" which means SQLite is not creating the shareable
in-memory DB.
Any clue why this is happening?
Thanks
Abhishek
--
Sent from: http://sqlite.1065341.n5.nabble.com/
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic