实体框架 + SQLite部署

发布于 2024-07-13 21:24:49 字数 567 浏览 5 评论 0原文

我有一个 ASP.NET MVC 应用程序,它通过实体框架使用 SQLite 数据库。 一切都可以在 VS 2008 的本地开发网络服务器上运行。

但是,将 Web 应用程序部署到我的服务提供商会导致此错误:

[ArgumentException: Unable to find the requested .Net Framework Data Provider.  It may not be installed.]
   System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1308959
   System.Data.EntityClient.EntityConnection.GetFactory(String providerString) +35

服务提供商评论说他们不支持 SQLite。 我认为 SQLite 独立于服务提供商的设置,因为它是 App_Data 可部署的。

有没有人有成功的实体框架+ SQLite 部署的经验?

干杯, -pom-

I have a ASP.NET MVC app that is using SQLite database through Entity Framework.
Everything works on VS 2008's local development webserver.

However, deploying the web app to my service provider causes this error:

[ArgumentException: Unable to find the requested .Net Framework Data Provider.  It may not be installed.]
   System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1308959
   System.Data.EntityClient.EntityConnection.GetFactory(String providerString) +35

Service provider has commented that they do not support SQLite. I had though that SQLite is independent of service provider's settings since it's App_Data deployable.

Has anyone experiences of a succesfull Entity Framework + SQLite deployment?

Cheers,
-pom-

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

零度℉ 2024-07-20 21:24:49

您不太可能再阅读本文,但您的 app.config(或者,对于您来说,web.config)中缺少以下内容:

<configuration>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" 
           description=".Net Framework Data Provider for SQLite"
           type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
  </system.data>
</configuration>

具体来说,如果您在链接到您的网站的库中使用 sqlite ,您必须将其添加到网站的配置文件中 - 而不是库!这是因为您加载提供程序的方式:本质上,您在运行时确定要加载哪个 dll,使用字符串“System.Data.SQLite”,并使用条目程序集的设置来找到适当的提供程序。

编辑:顺便说一句,当您编写具有 sqlite 依赖项的库时,您可以避免这种复杂性。 您不需要使用DbProviderFactories在运行时查找sql​​ite; 您也可以采用编译时依赖项,这样更容易管理。 然后,您可以忽略上面的 app.config 部分,而是将以下所有实例替换为:

DbProviderFactories.GetFactory("System.Data.SQLite").CreateConnection()

如果

System.Data.SQLite.SQLiteFactory.Instance.CreateConnection()

这样做,您将使用普通的库调用来创建连接,并且没有数据库提供程序的运行时选择。 这可能不太灵活,因为您无法再通过配置文件交换数据提供程序,但对于许多库来说这已经足够了。 不幸的是,如果您无法控制库代码,则这不是一个选择。

You're unlikely to be reading this anymore, but you're missing the following in your app.config (or, for you, web.config):

<configuration>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" 
           description=".Net Framework Data Provider for SQLite"
           type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
  </system.data>
</configuration>

Specifically, if you're using sqlite in a library which is linked into your website, you must add this to the config file of the website - not the library! This is because of how you're loading the provider: essentially, you're determining at runtime which dll to load, using the string "System.Data.SQLite", and locating the appropriate provider is done using the settings of the entry assembly.

Edit: By the way, when you're writing the library that has an sqlite dependancy, you can avoid this complexity. You do not need to use DbProviderFactories to look for sqlite at runtime; you can take a compile-time dependancy just as well, which can be easier to manage. Then you can ignore the above app.config section, and instead replace all instances of:

DbProviderFactories.GetFactory("System.Data.SQLite").CreateConnection()

with

System.Data.SQLite.SQLiteFactory.Instance.CreateConnection()

If you do so, you're using a plain library call to create the connection and there's no runtime selection of db provider. That can be less flexible since you can no longer exchange data providers via the config file, but for many libraries that's sufficient. Unfortunately, if you don't control the library code, this isn't an option.

|煩躁 2024-07-20 21:24:49

您是否尝试过将所需的 DLL 添加到应用程序的 bin 目录中? 您可能需要查看 Phil Haack 的文章 Bin 部署 ASP。 NET MVC 了解如何自动执行此操作的想法。

Have you tried adding the required DLL(s) to your application's bin directory? You might want to look at Phil Haack's article on Bin Deploying ASP.NET MVC for ideas on how to do this automatically.

本宫微胖 2024-07-20 21:24:49

SQLite 需要完全信任权限才能部署 ASP.NET 应用程序。 许多共享托管提供商不允许这样做。 你可能不想检查这个。

SQLite needs full trust permission for ASP.NET application deployment. Many shared hosting providers don't allow that. You might wan't to check this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文