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-
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.
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.
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.
Related
I have a VS 2012 Web Project Up. I have ODP.NET installed as we are an Oracle Workshop. I inherited a project that uses Oracle.ManagedAccess.Data and EF.
Upon running the project in VS 2012, I get the following error:
There is a duplicate 'oracle.manageddataaccess.client' section defined..
The solution was to disable the following line in web.config
<!--<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />-->
Which was fine. The project compiled but upon executing a simple command such as getting a password back where it has to read the database another error was tripped up:
System.Data.ConstraintException: Column 'InvariantName' is constrained to be unique. Value 'Oracle.ManagedDataAccess.Client' is already present.
Now I'm aware that the error is tripped up by ODP.NET and having it exist in the GAC thus the double error reporting.
Is there another line I should be commenting out or is there a way to disable ODP.NET briefly? I don't want to install that client as I use it for other projects.
thanks
I found the following on the Oracle site regarding the "There is a duplicate 'oracle.manageddataaccess.client' section defined.":
If your application is a web application and the above entry was added
to a web.config and the same config
section handler for "oracle.manageddataaccess.client" also exists in
machine.config but the "Version" attribute values
are different, an error message of "There is a duplicate
'oracle.manageddataaccess.client' section defined." may be
observed at runtime. If so, the config section handler entry in the
machine.config for "oracle.manageddataaccess.client" has to be removed from the machine.config
for the web application to not encounter
this error. But given that there may be other applications on the machine
that depended on this entry in the
machine.config, this config section handler entry may need to be moved to all
of the application's .NET config file on
that machine that depend on it.
I hope it helps.
I was getting the same error for an ASP.Net MVC project. I found that there is a version mismatch for oracle.manageddataaccess.client in the Web.config of the project, and machine.config in
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config, and
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config.
I had Version=4.122.18.3 in the Web.config and Version=4.122.1.0 in the machine.config.
I updated the version(replaced Version=4.122.1.0 of oracle.manageddataaccess.client with 4.122.18.3) in both the machine.config, and the problem resolved.
In my case I have multiple projects. One a Entity Framework data model, another which is an WCF Service using the EF Model, a WPF project using the WCF Service, and finally, my ASP.NET MVC prject, using the Entity Framework Data model directly.
We use Oracle and had a Nuget package oracle.manageddata. I used Version 12.1.21 in all the others, except my ASP project (which had version 12.1.22). After downgrading to what the other projects are using, my Web ASP is running again. Using different Nuget versions in various projects, in the same solution, doesn't seem to be such a good idea.
There are multiple ways to solve this problem. Not everyone has the luxury or desire to modify the machine.config (especially on a server). Perhaps the easiest way to solve this problem is to use bindingRedirect in your web.config (or app.config, if not a web application).
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.122.21.1" newVersion="4.122.21.1"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
NOTE: The version I am using is 4.122.21.1. Be sure you match your own version that you are using.
NOTE: The redirect is on Oracle.ManagedDataAccess, not Oracle.ManagedDataAccess.Client; this is a common mistake that developers make.
If you want to make the change in the machine.config, proceed carefully as this could have unanticipated consequences on other apps on the machine. The simplest modification is to change the version of the Oracle.ManagedDataAccess.Client section from a strong version to any version by using an asterisk "*".
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=*, Culture=neutral, PublicKeyToken=89b483f429c47342" />
If you need additional clarification, let me know and I can give more details.
I have a Service Client Library project which has its own
app.config
.
This project is referenced in my Web Application. The problem is My web application throws following exception
Could not find endpoint element with name 'HttpEndPoint' and contract 'ServiceLibReference1.IDalService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
There is nothing wrong with the service. If i directly refer my service in the web application it works fine as client configurations get added to the web.config. But my requirement is to keep it in a separate library project.
The reason for the exception is service configurations are not added to the web.config. Should i always add them manually? Should not VS add corresponding configurations into web.config whenever a service library is referenced? or am i missing something ?
thanks
Service libraries are, by design, intended to be used by (potentially) multiple different applications. Therefore, they don't use the app.config file included in the template - they will use the config file (web/app) of the application that is referencing them. This promotes code reuse - if you have certain methods that you are always using across multiple applications, it's easier to put them in a separate class library assembly. One benefit of that design is that you only need to change the code in one place to make the change effective for all using applications.
So yes, you will always need to add the service configuration to the specific application configuration file. Unfortunately, VS does not know to do this.
I have an asp.net mvc 5 website using EF, LocalDB and Code First Migrations. Requirements have now dictated that I need a need to add a console application into the mix to do some scheduled work. However this console app must call into the database functionality exposed in the web application. Also of note is that we are using LocalDB for development, but will switch to a 'proper' remote DB for production.
As such I have created a new console application within the project and added a reference to the web application so that I can call its repository functions. I know this probably isn't the best way to handle things.
For whatever reason though, when calling Save Changes on the database context from within the console application, nothing is saved to the LocalDB database. The Save function returns a number indicating that a number of rows were inserted.
I get the feeling I am making a schoolboy error somewhere. What could it be?
i`v used this in the past:
<add name="DefaultConnection"
connectionString="Server=(localdb)\v11.0;Database=WebPortalDb" providerName="System.Data.SqlClient"/>
If you want to use the functionality/database from one Project to another project then use the following::
1) Include the 'ConsoleProjectName.dll' file into your 'MVC' project's reference
2) Use that Dll into the namespace of your file.
(eg. using System.Data.Entity)
in the same way you have to use the DLL into your namespace.
3) make an object of the 'console' application's class and use the methods & other properties defined in that class.
May be this much information will be helpful for you.
This we are doing for n-tired architecture, where there are different layers (i.e. projects) in a solution to be linked with each other.
I have only few projects on my bag. In a previous desktop application when I wanted to store and use some application specific information I was using the app.config file.
Now I work on ASP.NET MVC 4 application and again I want to store some application specific information but this time I'm not sure. I have the web.config file which seems like a good place for this purpose but I'm not sure if it's the right place to store custom information there.
What is the right approach to do this? For example I want to save and extract path to directory on the file system where I'll save all my files. In ASP.NET MVC 4 what/where is the right place to do that?
The web.config file is what web application use where a desktop application uses app.config, and it's a good place to put application specific information.
You can add keys to the <appSettings> tag, and use them in the application just as you would if you put them in that tag in the app.config file. Example:
string path = ConfigurationManager.AppSettings["DataPath"];
Web.config is for ASP.NET and ASP.NET MVC; app.config is for desktop applications and DLLs.
If you need to storie any kind of parameter for your application that you can change without having to recompile, Web.config is the place to go.
Web.config is the web application version of app.config. Web.config seem like a good place for the configuration settings you're talking about.
Sometimes when you have a dll that had reference to desktop app.config, and when you import that MVC application you need to change the configuration data that used to be in app.config now to web.config.
Hi i am working on asp.net mvc app now.
I want to put all db logic to my mydbprovider.dll
The problem is in design, how can i change only db provider name in my web.config without recompile my own dll ?
I will use such .net providers as (oracle,mssql,postrgree)
Thanks and sorry for my bad english
as soon as you change the web.config then the site's appDomain will restart. This is unavoidable and only happens in the following scenarios:
Change of web.config
change to bin folder
Trigger of
numRecompilesBeforeAppRestart
what you need to do to be able to swap dal layers easily is to program to interfaces. There will be an interface that implements with the correct methods that you want to use and then any associated dal layer (mysql, sqlserver, oracle) will implement those methods
hopefully that will mean you are not bound to a specific implementation of a dal
paul