6

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-

3 Answers 3

13

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. This worked for me too: in a wpf application that referenced a class library with SQLite data access.
0

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.

2 Comments

Hi, thanks for an answer. Yep, I've seen Phil's blogpost. I can deploy normal ASP.NET MVC app just fine. It's the combination with Entity Framework + SQLite that is problematic. I've upped both System.Data.Entity.dll and System.Data.SQLite.dll to bin folder. No luck yet.
Hmmm. Are they in your assemblies section in the web config?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.