{"id":899,"date":"2016-01-25T20:22:04","date_gmt":"2016-01-25T10:22:04","guid":{"rendered":"http:\/\/www.moneystock.net\/wp_e\/?p=899"},"modified":"2016-08-06T00:19:02","modified_gmt":"2016-08-05T14:19:02","slug":"sqlite-in-net","status":"publish","type":"post","link":"https:\/\/moneystock.net\/wp_e\/2016\/01\/25\/sqlite-in-net\/","title":{"rendered":"SQLite in .Net"},"content":{"rendered":"<p>After using SQLite for a while, a few conclusions that I had were<\/p>\n<ol>\n<li>SQLite is quite stable enough to be used in corporate environment.<\/li>\n<li>SQLite is faster than SQLCE.<\/li>\n<li>For a SQLite admin, use the Firefox addon &#8211; \u00a0<a href=\"https:\/\/addons.mozilla.org\/de\/firefox\/addon\/sqlite-manager\/\" rel=\"nofollow\">https:\/\/addons.mozilla.org\/de\/firefox\/addon\/sqlite-manager\/<\/a><\/li>\n<li>SQL Server Compact Toolbox will be useful:\u00a0<a href=\"https:\/\/visualstudiogallery.msdn.microsoft.com\/0e313dfd-be80-4afb-b5e9-6e74d369f7a1\">https:\/\/visualstudiogallery.msdn.microsoft.com\/0e313dfd-be80-4afb-b5e9-6e74d369f7a1<\/a><\/li>\n<li>Both SQLite and SQLCE cannot be used in a condition that requires to write in DB concurrently. To make sure that an application does not access the DB concurrently, &#8216;lock&#8217; statement was used.<\/li>\n<li>Both can be used with Entity Framework, which is nice.<\/li>\n<\/ol>\n<p>Installation is relatively easy, but set up could be confused as some of tutorial does not work as it should be due to the version difference (?) and NuGet didn&#8217;t properly updated config file in my case, so I had to update it manually.<\/p>\n<p>I&#8217;ve current set up both SQLite and SQLCE with the versions as below.<\/p>\n<p>Entity Environment 6.0<br \/>\nData.Dqlite.EF6 1.0.98.0<br \/>\nSystem.Data.SqlServerCe 4.0<\/p>\n<p>Below is the configuration for SQLite and SQLCE to be used together.<\/p>\n<pre>&lt;connectionStrings&gt;\r\n &lt;add name=\"SQLiteLogContext\" connectionString=\"Data Source=D:\\Stash\\Projects\\AU\\WestPac\\CustomWebService\\WcfCustomService\\Log\\RTWS.sqlite\" providerName=\"System.Data.SQLite.EF6\" \/&gt;\r\n &lt;add name=\"SQLCELogContext\" providerName=\"System.Data.SqlServerCe.4.0\" connectionString=\"Data Source=D:\\Stash\\Projects\\AU\\WestPac\\CustomWebService\\WcfCustomService\\Log\\RTWS.sdf\" \/&gt;\r\n&lt;\/connectionStrings&gt; \r\n&lt;runtime&gt;\r\n &lt;assemblyBinding xmlns=\"urn:schemas-microsoft-com:asm.v1\"&gt;\r\n &lt;dependentAssembly&gt;\r\n &lt;assemblyIdentity name=\"EntityFramework\" publicKeyToken=\"b77a5c561934e089\" culture=\"neutral\" \/&gt;\r\n &lt;bindingRedirect oldVersion=\"0.0.0.0-4.4.0.0\" newVersion=\"4.4.0.0\" \/&gt;\r\n &lt;\/dependentAssembly&gt;\r\n &lt;\/assemblyBinding&gt;\r\n&lt;\/runtime&gt;\r\n&lt;entityFramework&gt;\r\n &lt;defaultConnectionFactory type=\"System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework\"&gt;\r\n &lt;parameters&gt;\r\n &lt;parameter value=\"System.Data.SqlServerCe.4.0\" \/&gt;\r\n &lt;\/parameters&gt;\r\n &lt;\/defaultConnectionFactory&gt;\r\n &lt;providers&gt;\r\n &lt;provider invariantName=\"System.Data.SQLite.EF6\" type=\"System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6\" \/&gt;\r\n &lt;provider invariantName=\"System.Data.SqlClient\" type=\"System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer\" \/&gt;\r\n &lt;provider invariantName=\"System.Data.SQLite\" type=\"System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral\" \/&gt;\r\n &lt;provider invariantName=\"System.Data.SqlServerCe.4.0\" type=\"System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact\" \/&gt;\r\n &lt;\/providers&gt;\r\n&lt;\/entityFramework&gt;\r\n&lt;system.data&gt;\r\n &lt;DbProviderFactories&gt;\r\n &lt;remove invariant=\"System.Data.SQLite.EF6\" \/&gt;\r\n &lt;add name=\"SQLite Data Provider (Entity Framework 6)\" invariant=\"System.Data.SQLite.EF6\" description=\".NET Framework Data Provider for SQLite (Entity Framework 6)\" type=\"System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6\" \/&gt;\r\n &lt;remove invariant=\"System.Data.SqlServerCe.4.0\" \/&gt;\r\n &lt;add name=\"Microsoft SQL Server Compact Data Provider 4.0\" invariant=\"System.Data.SqlServerCe.4.0\" description=\".NET Framework Data Provider for Microsoft SQL Server Compact\" type=\"System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91\" \/&gt;\r\n &lt;\/DbProviderFactories&gt;\r\n&lt;\/system.data&gt;<\/pre>\n<p>Useful links regarding SQLite in .Net C#<\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\">Tutorial<\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\"><a href=\"http:\/\/www.tutorialspoint.com\/\">http:\/\/www.tutorialspoint.com\/<\/a><\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\"><a href=\"http:\/\/www.codeproject.com\/Articles\/236918\/Using-SQLite-embedded-database-with-entity-framewo\">http:\/\/www.codeproject.com\/Articles\/236918\/Using-SQLite-embedded-database-with-entity-framewo<\/a><\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\">Good and concise article<\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\"><a href=\"https:\/\/damienbod.wordpress.com\/2013\/11\/14\/using-sqlite-with-net\/\">https:\/\/damienbod.wordpress.com\/2013\/11\/14\/using-sqlite-with-net\/<\/a><\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\">Best example<\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\"><a href=\"https:\/\/damienbod.wordpress.com\/2013\/11\/18\/using-sqlite-with-entity-framework-6-and-the-repository-pattern\/\">https:\/\/damienbod.wordpress.com\/2013\/11\/18\/using-sqlite-with-entity-framework-6-and-the-repository-pattern\/<\/a><\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\">Get VS13 DB designer with SQLite<\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\"><a href=\"http:\/\/stackoverflow.com\/questions\/25089346\/database-first-create-entity-framework-6-1-1-model-using-system-data-sqlite-1-0\">http:\/\/stackoverflow.com\/questions\/25089346\/database-first-create-entity-framework-6-1-1-model-using-system-data-sqlite-1-0<\/a><\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\">Setting for Performance<\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Consolas; font-size: 9.55pt;\"><span style=\"color: black; background: #EEEEEE;\">PRAGMA main.page_size = <\/span><span style=\"color: maroon; background: #EEEEEE;\">4096<\/span><span style=\"color: black; background: #EEEEEE;\">;<br \/>\nPRAGMA main.cache_size=<\/span><span style=\"color: maroon; background: #EEEEEE;\">10000<\/span><span style=\"color: black; background: #EEEEEE;\">;<\/span><\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Consolas; font-size: 9.55pt;\"><span style=\"color: black; background: #EEEEEE;\">PRAGMA main.cache_size=<\/span><span style=\"color: maroon; background: #EEEEEE;\">5000<\/span><span style=\"color: black; background: #EEEEEE;\">;<\/span><\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Consolas; font-size: 9.55pt; color: black;\"><span style=\"background: #EEEEEE;\">PRAGMA main.locking_mode=EXCLUSIVE;<br \/>\nPRAGMA main.synchronous=NORMAL;<br \/>\nPRAGMA main.journal_mode=WAL;<\/span><\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 9.0pt; color: #595959;\">Pasted from &lt;<a href=\"http:\/\/stackoverflow.com\/questions\/784173\/what-are-the-performance-characteristics-of-sqlite-with-very-large-database-file\">http:\/\/stackoverflow.com\/questions\/784173\/what-are-the-performance-characteristics-of-sqlite-with-very-large-database-file<\/a>&gt;<\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\">Keep the max size of database<\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\"><a href=\"http:\/\/stackoverflow.com\/questions\/5987042\/how-do-you-efficiently-trim-an-sqlite-database-down-to-a-given-file-size\">http:\/\/stackoverflow.com\/questions\/5987042\/how-do-you-efficiently-trim-an-sqlite-database-down-to-a-given-file-size<\/a><\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\">SQLite Dispose or Close issue<\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\"><a href=\"http:\/\/stackoverflow.com\/questions\/8511901\/system-data-sqlite-close-not-releasing-database-file\">http:\/\/stackoverflow.com\/questions\/8511901\/system-data-sqlite-close-not-releasing-database-file<\/a><\/p>\n<p lang=\"en-GB\" style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\"><a href=\"http:\/\/stackoverflow.com\/questions\/12532729\/sqlite-keeps-the-database-locked-even-after-the-connection-is-closed\/12679840#12679840\">http:\/\/stackoverflow.com\/questions\/12532729\/sqlite-keeps-the-database-locked-even-after-the-connection-is-closed\/12679840#12679840<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After using SQLite for a while, a few conclusions that I had were SQLite is quite stable enough to be used in corporate environment. SQLite is faster than SQLCE. For a SQLite admin, use the Firefox addon &#8211; \u00a0https:\/\/addons.mozilla.org\/de\/firefox\/addon\/sqlite-manager\/ SQL Server Compact Toolbox will be useful:\u00a0https:\/\/visualstudiogallery.msdn.microsoft.com\/0e313dfd-be80-4afb-b5e9-6e74d369f7a1 Both SQLite and SQLCE cannot be used in a&hellip; <a class=\"more-link\" href=\"https:\/\/moneystock.net\/wp_e\/2016\/01\/25\/sqlite-in-net\/\">Continue reading <span class=\"screen-reader-text\">SQLite in .Net<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128,203],"tags":[184,95,100,210,209],"class_list":["post-899","post","type-post","status-publish","format-standard","hentry","category-db","category-library","tag-net","tag-c","tag-entity-framework","tag-sqlce","tag-sqlite","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/comments?post=899"}],"version-history":[{"count":6,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/899\/revisions"}],"predecessor-version":[{"id":974,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/899\/revisions\/974"}],"wp:attachment":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/media?parent=899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/categories?post=899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/tags?post=899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}