Page 1 of 1
SQLite - how to create
Posted: Mon 07 Jul 2014 17:03
by ashlar64
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!
Re: SQLite - how to create
Posted: Mon 07 Jul 2014 20:45
by ashlar64
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.
Re: SQLite - how to create
Posted: Tue 08 Jul 2014 07:44
by MariiaI
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.
Re: SQLite - how to create
Posted: Mon 14 Jul 2014 15:50
by ashlar64
Thanks that worked. Also thanks for pointing out dbmonitor. That will definitely be useful in the future.
Re: SQLite - how to create
Posted: Tue 15 Jul 2014 07:17
by MariiaI
If you have any further questions, feel free to contact us.