This is a migrated thread and some comments may be shown as answers.

Create SQLite database during runtime

8 Answers 325 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erik
Top achievements
Rank 1
Erik asked on 31 Jul 2012, 09:32 AM
I want to create a SQLite database file during runtime, does someone know how I can achieve this?

8 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 31 Jul 2012, 09:48 AM
Hi Erik,
You can use the schema handler to execute all schema related operations:

var schema = context.GetSchemaHandler();
var exists = schema.DatabaseExists();
var script = "";
if (exists == false)
{
    schema.CreateDatabase();
    script = schema.CreateDDLScript();
}
else
{
    script = schema.CreateUpdateDDLScript(new SchemaUpdateProperties() { CheckExtraColumns = false });
}
if (string.IsNullOrEmpty(script) == false)
{
    schema.ExecuteDDLScript(script);
}


Regards,
Jan Blessenohl
the Telerik team
OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
0
Erik
Top achievements
Rank 1
answered on 31 Jul 2012, 09:54 PM
Hi Jan,

Thanks for your reply.

Using your code, the SQLite database file is created, however the line
script = schema.CreateDDLScript();
returns an empty string. Am I missing a step?

Additionally, is it possible to specify file name and location for the SQLite database file?
0
Ady
Telerik team
answered on 03 Aug 2012, 10:05 AM
Hi Erik,

 Do you have classes in your Domain model? Can you check the 'Update Schema' property for each domain class (press F4 to open the Properties window and check the property value) ? It should be set to 'true'.
In cae this does not work can you send me your .rlinq file so that I can have a deeper look at it?

Regards,
Ady
the Telerik team
OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
0
Erik
Top achievements
Rank 1
answered on 04 Aug 2012, 08:34 AM
Hi Ady,

Setting the update schema property to true fixes the schema creation :)

I want to be able to specify the SQLite file name and location during runtime, do you know if this is possible?
0
Ady
Telerik team
answered on 07 Aug 2012, 04:05 PM
Hello Erik,

 You can specify the fully qualified file name in the 'DataSource' property of the connection string and then use this connection string to construct the context instance. What does your connection string look like now? What is the value specified with the 'DataSource' keyword?

Kind regards,
Ady
the Telerik team
OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
0
Erik
Top achievements
Rank 1
answered on 17 Aug 2012, 06:30 PM
Hi Ady,

The Connection.ConnectionString is:
"data source=C:\Users\xxxx\MyFolder\testdb;failifmissing=True;enlist=False"

Connection.DataSource is:
"testdb"

When I try to modify the Connection.ConnectionString during runtime I get a System.InvalidOperationException:
"Cannot change the connection string for an OAConnection."
0
Accepted
Ady
Telerik team
answered on 20 Aug 2012, 03:28 PM
Hi Erik,

 Here is some sample code of how to specify the connection string at runtime

string cs = "data source=C:\\TestFolder\\testdb;failifmissing=True;enlist=False";
var context = new EntitiesModel(cs);
var schema = context.GetSchemaHandler();

Regards,
Ady
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Amelie
Top achievements
Rank 1
answered on 07 Apr 2015, 12:00 PM
I
hope it will helpful for you

http://sqliteviewer.blogspot.com/2015/04/create-sqlite-database-file.html
Tags
Databases and Data Types
Asked by
Erik
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Erik
Top achievements
Rank 1
Ady
Telerik team
Amelie
Top achievements
Rank 1
Share this question
or