SQLite - how to create

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
ashlar64
Posts: 75
Joined: Thu 04 May 2006 18:56

SQLite - how to create

Post by ashlar64 » Mon 07 Jul 2014 17:03

Hello,

I need to evaluate LinqConnect with SQLite. One of the things we need to do is be able to create a new md file in code from our model (model first). Could someone show me a some code that would allow us to do this?

Thanks!

ashlar64
Posts: 75
Joined: Thu 04 May 2006 18:56

Re: SQLite - how to create

Post by ashlar64 » Mon 07 Jul 2014 20:45

I'm gonna answer my own question...

This code works:
System.Data.SQLite.SQLiteConnection.CreateFile("c:\\temp\\temp.db3");
DataContext1 d = new DataContext1("Data Source=C:\\temp\\temp.db3");
d.Connection.Open();
d.CreateDatabase(false, true);
d.SubmitChanges();
Class1 c = new Class1();
c.Property1 = "hi";
c.Property2 = "sfd";
d.Class1s.InsertOnSu(c);
d.SubmitChanges();

I was having a issue since I wasn't using hte very first line of code.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: SQLite - how to create

Post by MariiaI » Tue 08 Jul 2014 07:44

There is no need in these lines in your code:

Code: Select all

System.Data.SQLite.SQLiteConnection.CreateFile("c:\\temp\\temp.db3"); // JIC: you can use Devart.Data.SQLite.SQLiteConnection for such cases
and

Code: Select all

d.Connection.Open();
///
 d.SubmitChanges();
New database file will be created and the connection will be opened automatically when performing the CreateDatabase(false,true) method. Please refer to:
http://www.devart.com/linqconnect/docs/?DDL.html
http://www.devart.com/linqconnect/docs/ ... lean).html

Rewrite your code in the following way:

Code: Select all

DataContext d = new DataContext("Data Source=c:\\temp\\temp.db3");
 d.CreateDatabase(false, true);
 Class1 c = new Class1();
 c.Property1 = "hi";
 c.Property2 = "sfd";
 d.Class1s.InsertOnSubmit(c);
 d.SubmitChanges();
You can try monitoring your application via the dbMonitor tool to see the results. For example:

Code: Select all

Devart.Data.Linq.Monitoring.LinqMonitor lm = new Devart.Data.Linq.Monitoring.LinqMonitor(){ isActive = true };
For more information please refer to
http://www.devart.com/linqconnect/docs/?Monitoring.html
http://www.devart.com/linqconnect/docs/ ... nitor.html

Please tell us about the results.

ashlar64
Posts: 75
Joined: Thu 04 May 2006 18:56

Re: SQLite - how to create

Post by ashlar64 » Mon 14 Jul 2014 15:50

Thanks that worked. Also thanks for pointing out dbmonitor. That will definitely be useful in the future.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: SQLite - how to create

Post by MariiaI » Tue 15 Jul 2014 07:17

If you have any further questions, feel free to contact us.

Post Reply