Windows Service referencing Entity Framework 6 fails when deployed - c#

I have a .Net 4.5.1 Console application configured as a Windows Service (derives from ServiceBase), using EntityFramework 6.1 installed via the Nuget package.
It works fine running locally (where I run it as a console application).
I deploy it to a Windows Server 2008 machine which has .Net 4.5.2 installed, register it as a Windows Service, and successfully start the service.
The service has a timer that does work every 90 seconds. The first time it does work (after 90 seconds), when it attempts to read from a SQL Server database, it fails with this error message:
System.Configuration.ConfigurationErrorsException: The 'DbProviderFactories' section can only appear once per config file.
I looked into the 2 machine.config files on the machine (in the .Net 2 and 4 folders) and verified that each has only a single DbProviderFactories section. There is no DbProviderFactories in my service app.config. The EventViewer does not have any information. I reinstalled .Net 4.5.2 and restarted the server to no avail.
How can I find out where is it trying to load two DbProviderFactories sections?
I'm adding this next bit of information just in case it is germane.
The second time the service does work (after 180 seconds), when it attempts to read from the same SQL Server database it fails with a different error message:
The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded.
This second error message is similar to this issue:
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'
but unfortunately I've already implemented all the suggestions to fix it.
I installed Entity Framework 6 from the Nuget package in both my data access layer AND my Console App windows service. The NuGet installer inserted the required sections into my app.config:
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
and
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
I deployed what Visual Studio puts in my bin folder when I build. The deployment includes both EntityFramework.dll and EntityFramework.SqlServer.dll
My database connection string is:
<connectionString value="data source=SQLServerName;initial catalog=DatabaseName;integrated security=true;persist security info=True" />
The windows service runs under an identity that has access to the database.
This second error continues until I shut off the service.

Turned out this was the answer: The 'DbProviderFactories' section can only appear once per config file
When I stated "I looked into the 2 machine.config files on the machine (in the .Net 2 and 4 folders) and verified that each has only a single DbProviderFactories section." that was false. There was a duplicate, I simply did not see it the first time I looked.

Related

Visual Studio 2017 not showing MySQL in connection list

I am using "Visual Studio 2017 Professional". I can not get a project to recognize that MySQL is an available DB option. MySQL does not show up in the list of possible connections when I create a new model. I know that there are tons of SO questions and other web pages on this topic because I have tried a lot of the suggestions. Each is subtlety different in cause and solution. None of the solutions seem to work for me.
I have tried the following with VS 2017 and 2015 with the same results. I have older versions of VS available but it didn't seem worthwhile to march that far back. I have also tried installing the latest and older versions of MySQL both with the "Community Installer" and the standalone msi's when necessary. I went back to the "latest" pre-6.10 version of MySQL.
To begin, this saga started last week when I noticed that nuget had MySQL package updates available. I applied them and then went to upgrade the installed MySQL componants with the Community Installer. The nuget changes did apply. The Community Installer could not uninstall MySQL for VS though. The system installer could not uninstall it. Rebooting and power-cycling did nothing.
On the advice of our local tech support folks I used a third party uninstaller that turned out to be more aggressive than we imagined. It seems to have randomly stommped across the registry erasing whatever it found. Long story short(er), I ended up having my machine reimaged. So, I have a fresh windows install.
Given the fresh Win10 platform, I installed the various things I normally use including the VS versions I typically use. I installed the latest Community MySQL installer. I did a "custom" MySQL install because I don't need a server on this device or fabric or many other things.
I finished the basic reinstall of everything then rebooted just to be sure. I started VS 2017 and created a new web app with the latest available version of .Net (4.6.1). I applied nuget updates and added EntityFramework and MySQL.Data. I then tried to create a new "code first" model.
I can get to the point where I am asked to create a connection. When I click the button the list of available DB providers only shows MS SQL.
I have seen the articles that say to add lines to Web.config and I have seen the MySQL .Net Connector docs that say the same things. I can see the MySQL entries in Web.config but they do not show up when creating a connection.
An oddity is that I can go to Tools -> Connect to Database and see EVERY DB type my machine knows about including MySQL. I can create the connection string and it works. I can see the DB in "Server Explorer` but that doesn't make it available to code.
Ok, I have followed the above steps over and over including downgrading the version of EntityFramework as well as the MySQL version.
My most recent attempt has me back to the latest version of VS and MySQL. The relevant (I think) section of the Web.config file follow. Note the defaultConnectionFactory entry is LocalDbConnectionFactory. I have changed that to SqlConnectionFactory but it has not made a difference. I have also changed the order of the providers and the order of the major blocks.
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
</provider>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add description=".Net Framework Data Provider for MySQL" invariant="MySql.Data.MySqlClient"
name="MySQL Data Provider"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.10.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
Edit
My current impression is that VS 2017 is an unusable mess masquerading as a released, salable product. I have returned to 2015.
I have come closer to getting this to work in 2015. I have the latest MySQL items for VS and .Net installed. I have downgraded the nuget EF package to 6.0 and the MySql packages to 6.8.8.
In, what I am now calling, "the good old days" I could add a new model to an MVC project by selecting the Models folder; selecting "Add New Item"; choosing ADO.Net model; select a connection option (MySQL); enter the connection info; choose DB First or Code First and wait for the scaffolding fun to finish.
Now, I have to first go to Tools -> Connect to Database and create a conenction to a MySql DB. If I do not do this I will not see MySQL in the list of possible connections later. I then clean and build the project. Next i try to create the model as above. Noe I can see the MySQL connection option and I can enter the DB creds and test the connection.
The next step is to choose DB First or Code First. In either case, clicking the "next" button flashes a blank pop-up that then vanishes. No errors are shown and no connection is made.
It was never this hard in the past.
I have tried a lot of different MySQL and EF versions on 2015 and 2017 at this point. If there is a magic combo please tell me.
I have been fighting this fight for two weeks. I FINALLY found a combo of versions that works for me. The following was applied to a pristine re-image of my Win10 desktop two weeks ago. All patches were applied to system software before starting to deal with MySql.
Just this morning I re-read the post in this thread (MySql Forums): https://forums.mysql.com/read.php?174,659102,660369#msg-660369
I thought that I had tried those suggestions before but I must have messed up one of the versions. I think that poster's basic strategy is sound. In my case I uninstalled all local MySql parts and the installer.
I downloaded MySQL for Visual Studio - the Latest Development version (2.0.5 msi as of this writing) and installed that.
I found the OLD versions of the .Net Connector and installed 6.9.11
In VS 2017 I created a dummy project using .Net 4.6.1.
I applied pending VS updates.
I built the project.
I went to "Project -> Manage Nuget Packages" and installed / downgraded EntityFramework to 6.0.
I installed MySql.Data, MySql.Data.Entity and MySql.Web all at version 6.9.11
I cleaned and built the project then tried to add a new "Code First" model from a MySql DB... IT WORKED!
Thank you 7 Reeds for coming back with an answer. It led me to get it working, although I did it slightly differently.
In VS 2017 to connect to MySQL 5.6:
Uninstall any MySQL products from the machine
Set Target framework to .NET Framework 4.5.2
Uninstall EntityFramework and any MySQL packages in Nuget
Install MySql.Data.Entity (6.10.7)
It will also install the needed versions of the Nuget packages MySql.Data (6.10.7), EntityFramework (6.1.3), and BouncyCastle (1.8.3.1).
The MySql.Data.Entity package says it depends of Google.Protobuf, but it didn't install it and it works fine for me.
It added References in my project to BouncyCastle.Crypto (1.8.3.0), EntityFramework (6.0.0.0), MySQL.Data (6.10.7.0), and MySql.Data.Entity.EF6 (6.10.7.0).
Close Visual studio
Install 'MySQL for Visual Studio' (1.2.8)
Install 'Connector/NET' (6.10.7)
Delete the bin and obj folders
Open Visual Studio and Rebuild Solution
Add New Item > ADO.NET Entity Data Model > Now you're in the wizard
Select EF Designer from database
On the next screen ('Entity Data Model Wizard'), click New Connection...
On the 'Connection Properties' screen click the Change... button for the 'Data source'
You should be able to select the MySQL Database as the 'Data source'
The 'Data provider' should auto-populate with .NET Framework Data Provider for MySQL
Yay! Continue on like you normally would
For posterity, here's the app.config for my WPF application:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v13.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.10.7.0" newVersion="6.10.7.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<connectionStrings>
<add name="MyDB" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=MySql.Data.MySqlClient;provider connection string="server=my.example.com;user id=NotMyRealUserID;password=NotMyRealPassword;persistsecurityinfo=True;database=MyDatabase"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
I'm not sure what created this, but I have a 'User variable' in my 'Environment Variables' named MYSQLCONNECTOR_ASSEMBLIESPATH with value C:\Program Files (x86)\MySQL\MySQL Connector Net 6.10.7\Assemblies\v4.5.2
At appsettings.json:
"ConnectionStrings": { "DefaultConnection": "Server=localhost;database=MusicStoreDB;user id=root;Charset=utf8;" },
At ConfigureServices() in Startup.cs :
using Microsoft.EntityFrameworkCore; using MySql.Data.MySqlClient; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection;
... services.AddDbContext(options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")));
Note: Change to:
UseMysql <-------------- When using Pompelo EntityFrameworkCore

Connection String in Unit Test App.Config is ignored: SQLExpress gets set to LocalDB

I have a load of unit tests that were running fine in Visual Studio 2013. I dont know if it is related, but I can't think of what else might have changed. I have moved my project to VS2015.
Now whenever I run my unit tests, all the tests that use a data context fail with an error indicating they are trying to use (localdb)\V11.0 and integrated security to access the database.
However, my development database is on .\sqlexpress and has a SQL login.
I've been through every config file, including the app.config in the unit test project, and they all specify the correct database. If I debug step through the code I can reach the line where the data context is created and inspect its properties and see the connection string is wrong, but I can't see where it is coming from.
Here's the relevant bit of my test project's app.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="speedEntitiesDev" connectionString="metadata=res://*/mydb.csdl|res://*/mydb.ssdl|res://*/mydb.msl;provider=System.Data.SqlClient;provider connection string="Server=.\sqlexpress;Database=thedatabase;User ID=theuser;Password=thepassword;Connection Timeout=30;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Server=.\sqlexpress;Database=thedatabase;User ID=theuser;Password=thepassword;Connection Timeout=30;MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
When I step into the unit test this is what the property inspector says is the value of the connection string is:
"Data Source=(localdb)\\v11.0;Initial Catalog=thedatabase;Integrated Security=True"
Note that the database name is correct, but everything else is wrong.
I did previously have a database hosted locally in localdb but after upgrading my development computer I stopped using it.
UPDATE:
I've discovered that if I rename the connection in the above file, then this breaks the test in a different way. Then I get an error that the connection string is not found:
System.InvalidOperationException: No connection string named 'speedEntitiesDev' could be found in the application config file..
Other changes to the connection string also have an effect (like if I change the database name, the connection goes to the new database name, and uses the login and password I supply.)
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Cannot open database "thedatabase123" requested by the login. The login failed. Login failed for user 'theuser'..
When I set the connection string back to "thedatabase" it resets to using localdb and integrated security. It's like it's got an alias going or something.
After diving through the code for a few days, I noticed that in one older library referenced by every class tested by every failing test, there was a data update written as:
dc.SubmitChanges();
and it hit me, this class was using LINQ to Sql instead of Entity Framework. Somehow the class using LINQ to Sql was altering the connection string and defaulting to (localdb) which was what we were using when that library was written.
I changed the class to use Entity Framework instead and suddenly all my tests started respecting the connection string again.
This was weird because
The old referenced library didn't actually do any data updates any more (the data update code in it was legacy and long since placed elsewhere)
The old library didn't even have a valid reference to the data class that supplied its connection string
Despite this, just referencing the old library via the unit tests caused connection string weirdness.

Entity Framework 6.1.1 and Npgsql 2.2.3: Compatible Entity Framework database provider could not be found

I am working on a project using EntityFramework 6.1.1 and npgsql 2.2.3 within Visual Studio 2012 Update 4. To do so I installed npgsl using the supplied setup and installed the nuget packages "Npgsql" and "Npgsql for Entity Framework" (and "EntityFramework" itself, of course).
Every thing used to be fine: I could successfully access my database for a while - until at some day everything "blew up".
This is the event history:
Fixing compiler errors after a major code upgrade I encountered these error messages:
"could not load npgsl.EntityFrameworkLegacy assmbly" (I did neither install nor reference this assembly)
A whole bunch of "Metadata file 'xxx' could not be found" errors where 'xxx' referred to all my own project assemblies
I've found possible solutions the "Metadata file" problems - like deleting the .suo file, checking the project build order and so on. None of them fixed the problem. So I deleted
the .edmx file (and thus all automatically generated database access files) from my project. This fixed the "Metadata file" problems - introducing "unresolved symbols" of course.
I tried to add a new "ADO.NET Entity Data Model" to my project to regain database access. Only all PostgreSQL database connections where not listed any more in the connection list.
Also I could not create new PostgreSQL connections because this data source was not listed. Though this did not affect the global "data connections" dialog within
Visual Studio: here I could still access my PostgreSQL connections.
I reinstalled npgsql using the setup. Now I could create a new "ADO.NET Entity Data Model" and connect to my PostgreSQL database. But this time I'm getting the error message:
"Your project references the latest version of Entity Framework; however, and Entity Framework database provider compatible with this version could not be found [...]". This is
where I am stuck now.
My current setup is:
the project refers to the following assemblies:
EntityFramework 6.1.1 for .NET 4.5
EntityFramework.SqlServer 6.1.1 for .NET 4.5
Npgsql 2.2.3 for .NET 4.5
Npgsql.EntityFramework 2.2.3 for .NET 4.5
This is my app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
</configuration>
I have this in my machine.config (both 32bit and 64bit):
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.3.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
</DbProviderFactories>
</system.data>
Of dourse I tried to rebuild my solution before adding the new model. But this didn't help.
Are there any other configuration issues I may have missed?
Anybody who could explain me my why all this happened at all?

Entity Framewok Code First "ADO.NET provider not found" with local SQL Server CE DLL's

I am writing a C# application which uses SQL Server CE 4.0 files, which are accessed through the Entity Framework 6.0 via code-first. (The application needs to be able to use local dll's for the SQL Server CE connection i.e. the application needs to be XCOPY deployable). The application runs fine on my development machine, but on other machines (e.g. VMs with just Win7 and .NET 4.0), I get an ArgumentException:
The ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.
The inner exception message says:
Unable to find the requested .Net Framework Data Provider. It may not be installed.
I have searched Google and SO and most of the comments indicate ensuring the App.config file is correct. I believe mine is (default connection factory and provider sections), but here are the contents:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
</configuration>
The build folder includes the following files (in addition to the application-specific files, of course):
EntityFramework.dll
EntityFramework.xml
EntityFramework.SqlServer.dll
EntityFramework.SqlServer.xml
EntityFramework.SqlServerCompact.dll
EntityFramework.SqlServerCompact.xml
In each of the amd64 and x86 subfolders are the following files:
sqlceca40.dll
sqlcecompact40.dll
sqlceer40EN.dll
sqlceme40.dll
sqlceqp40.dll
sqlcese40.dll
I am certain the program runs on the development machine because SQL Server CE has been installed, but how do I get it to run using just local SQL Server CE dll's on other machines?
See http://tech.aendeavors.com/2011/06/09/bin-deploy-sqlce-4-0-and-ef-4-1/
It seems the relevant bits you might be missing are:
Make sure System.Data.SqlServerCe is referenced and set to "Copy
local" in properties.
Add the following to app.config:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<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"/>
</DbProviderFactories>
</system.data>
I was facing the same problem today.
After reinstalling EF several times, what solved my problem was referencing EF in my Console project along with the DAL project (the one that actually uses EF).
If you're using a reference that in turn references EF, you gotta add it to this project as well.
Sorry about the late response - actually, there's a really simple solution:
If you investigate the packages\EntityFramework.6.1.3\lib\net45 folder, you'll notice that there's another dll that's already in there - EntityFramework.SqlServer.
Simply add a reference to that, and everything will work.
I had the same issue and nothing worked for me. The only thing that resolved my this issue for me was to uninstall SQL Server Compact from my machine (via add/remove programs) and re-install it.
In my case, "EntityFramework.SqlServerCompact" package was missing. Just wanted to share if in case it can save someone's day!

ClickOnce deploy of WPF app with SQL Server Compact database

I read this post which apparently solves the issue with WPF app publishing which has SQL Server Compact dependency. I went through all the steps prescribed by the author of this post but it just doesn't work for me. Once I add all the DLLs from SQL Server Compact "private" folder my app crashes on startup. The difference is that I use .NET 4.5 while the example deals with 4.0 I am not sure if that is the core of the problem but it just doesn't work with those settings.
My app is crashing with the following exception :
System.Windows.Markup.XamlParseException
Here is my app.config (including add on from the article ) :
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="TypeAppRelease.Properties.Settings.MyDatabase_1ConnectionString"
connectionString="Data Source=D:\XXXXXX\XXXXX\XXXXXXX\externals\MyDatabase#1.sdf;Password=XXXXXXX;Persist Security Info=True"
providerName="Microsoft.SqlServerCe.Client.4.0" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0"/>
<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.1,
Culture=neutral,
PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
One more thing. I came to this because doing just ClickOnce publishing produced installation file which didn't work complaining that
The application is missing required files ....
So that lead me to the solution I linked above which also seems not to work.
Update:
I would like to extend on this problem because until not I haven't resolved it.
I decided to put aside ClickOnce deployment and just test Debug/Release builds on 2 machines:1) With SQL Compact Server installed ;2) Has only NET framework installed.
The App works ok on the first machine and fails on the second.That is pretty logical because the first one has Compact SQL installed and running.
Next I removed the server installation from the first machine and ran the app again.It still works , but not for the second PC .The error I am getting is
System.IO.FileLoadException
I can't figure out why I am getting it and why I am not getting the same on the first machine.
Maybe it is 64 /32 bit OS thing? PC1 runs Windows 7 64bit while PC2 x86.
I you use ADO.NET objects (SqlCeCommand, DataSet) instead of Entity Framework (as described in my blog post) you must reference System.Data.SqlServerCe.dll in your project folder (assembly version 4.0.0.1) and NOT the dll in your GAC (assembly version 4.0.0.0). I have updated my blog post with that information.

Categories