{"id":2733,"date":"2025-05-13T16:55:25","date_gmt":"2025-05-13T08:55:25","guid":{"rendered":"https:\/\/www.xfan.top\/?p=2733"},"modified":"2025-05-28T16:27:16","modified_gmt":"2025-05-28T08:27:16","slug":"c-asp-net-entity-framework-sqlite%e6%95%b0%e6%8d%ae%e5%ba%93-web-config-sqliteconnection%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%9c%80%e4%bd%b3%e9%85%8d%e7%bd%ae%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.xfan.top\/index.php\/2025\/05\/13\/2733\/","title":{"rendered":"C# ASP.NET Entity Framework SQLite\u6570\u636e\u5e93 Web.config SQLiteConnection\u5b57\u7b26\u4e32\u6700\u4f73\u914d\u7f6e\u65b9\u6cd5"},"content":{"rendered":"<p>Web.config \u4e2d\u914d\u7f6e<\/p>\n<pre><code>&lt;configuration&gt;\n    ...\n    &lt;connectionStrings&gt;\n        &lt;add name=&quot;SQLiteConnection&quot; connectionString=&quot;Data Source=|DataDirectory|\\crm2_fts5_test.sqlite;version=3;datetimeformat=CurrentCulture;Pooling=True;Max Pool Size=100;Min Pool Size=5;Cache Size=10000;&quot; providerName=&quot;System.Data.SQLite&quot;\/&gt;\n    &lt;\/connectionStrings&gt;\n    ...<\/code><\/pre>\n<p><code>|DataDirectory|<\/code>\u8868\u793a\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\u7684<code>\\App_Data<\/code>\u76ee\u5f55\uff0c\u5c06\u6570\u636e\u5e93\u6587\u4ef6\u7f6e\u4e8e\u5176\u4e2d\uff0c\u5728\u6b64\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u5b57\u7b26\u4e32\u5373\u53ef\u3002<\/p>\n<p>DbContext\u4e2d\u5982\u4e0b\u5199\u6cd5\uff1a<\/p>\n<pre><code>public class AppDbContext : DbContext\n{\n    public AppDbContext() : base(&quot;name=SQLiteConnection&quot;)\n    {\n    ...\n    }\n    ...<\/code><\/pre>\n<p><code>|DataDirectory|<\/code>\u7684\u4f4d\u7f6e\u4e5f\u53ef\u4fee\u6539\uff0c\u5728<code>Global.asax<\/code>\u4e2d<code>public class Global : HttpApplication<\/code>\u7684<code>Application_Start<\/code>\u65b9\u6cd5\u4e2d\uff0c\u6267\u884c<\/p>\n<pre><code>string customDataPath = Server.MapPath(&quot;~\/DATA&quot;);\nAppDomain.CurrentDomain.SetData(&quot;DataDirectory&quot;, customDataPath);<\/code><\/pre>\n<p>\u5c31\u53ef\u4ee5\u5427<code>|DataDirectory|<\/code>\u8bbe\u4e3a\u7f51\u7ad9\u76ee\u5f55\u4e0b\u7684<code>\/DATA<\/code>\u6587\u4ef6\u5939\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Web.config \u4e2d\u914d\u7f6e &lt;configuration&gt; &#8230; &lt;connection [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2733","post","type-post","status-publish","format-standard","hentry","category-webappdev"],"_links":{"self":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/comments?post=2733"}],"version-history":[{"count":3,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2733\/revisions"}],"predecessor-version":[{"id":2771,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2733\/revisions\/2771"}],"wp:attachment":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/media?parent=2733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/categories?post=2733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/tags?post=2733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}