I'm developing a WPF application using Entity Framework 4 and SQL Server CE database 3.5 and it's correctly working.
However I'd like to have this application to run on a machine with .Net Framework 4 installed but without the SQL Server Compact 3.5 drivers. And no installer. Is it possible?
I have tried the following:
create a section in the app.config
<configuration>
<connectionStrings>
<add name="DbEntities"
connectionString="metadata=res://*/Model.Model1.csdl|res://*/Model.Model1.ssdl|res://*/Model.Model1.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=|DataDirectory|\Data\Database1.sdf""
providerName="System.Data.EntityClient"/>
</connectionStrings>
<system.data>
<DbProviderFactories>
<add name="SQL Server Compact Edition Data Provider"
invariant="System.Data.SqlServerCe"
description=".NET Framework Data Provider for Microsoft SQL Server Compact Edition"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
</configuration>
add references to System.Data.SqlServerCe and System.Data.SqlServerCe.Entity and allow local copy
build the application and copy it on a machine without SQL Server CE drivers installed. When it comes to create the data context I keep getting this error :
System.ArgumentException: The specified store provider cannot be found in the configuration, or is not valid. --->
System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
Am I losing time? Or should I just switch to SQLite?
Thanks!
EDIT:
Thanks to josemiguel.torres' answer, I check at this post detailling how to achieve this. However, I still have an assembly error.
"System.IO.FileLoadException: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)"
So I had a look at this other post explaining how to fix this issue.
After adding some assembly binding:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
<bindingRedirect oldVersion="3.5.1.0-3.5.1.50" newVersion="3.5.1.50"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
It still doesn't work ... :|
Error message is similar :
System.IO.FileLoadException: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
I'm out of solution. Anyone?
EDIT 2:
1.I have uninstalled all the Microsoft "SQL Server Compact Edition" versions from my machine.
2.I checked the machine.config version : there is no entries in the DbProviderFactories section.
3.I downloaded the 3.5 SP2 drivers from there and installed the x86 package.
4.I check my machine.config (v4 x86) and the following entries has been created under the DbProviderFactories node:
<add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
Why is it 3.5.0.0 and not 3.5.1.50???
juste in case: my dev machine is on Win7 x64 and target machine is WinXP x86.
Install 3.5 SP2, and modify the app.config as follows:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ChinookEntities" connectionString="metadata=res://*/Chinook.csdl|res://*/Chinook.ssdl|res://*/Chinook.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=C:\Users\erik.COMMENTOR\Documents\Visual Studio 2010\Projects\SqlCeTest\Chinook.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.3.5" />
<add name="Microsoft SQL Server Compact Data Provider 3.5" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.1.50, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly xmlns="">
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="3.5.1.0-3.5.1.50" newVersion="3.5.1.50" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Make sure to use the System.Data.SqlServerCe.dll and System.Data.SqlServerCe.Entity.dll from the C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Private folder
I gave up with SQL CE 3.5 and switched to 4.0. It's working fine, thanks to this article.
Thanks Erik ;)
Related
Okay my project has a separate class library that has all the EnitityFramework version 6.1.3 code and settings.
I can not get this to connect to anything other than my local sql db
I can connect to my sql box 192.111.111.111\sql_box with SQL manager, SQL server object explorer and LINQpad. so it is there and connection string is correct.
I think I am now meant to be doing code based configuration
so my App.cong looks like this
<?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>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<entityFramework codeConfigurationType="MyProject.CodeConfig, MyProject">
</entityFramework>
</configuration>
and I have also create and class that derives from DbConfiguation
public class CodeConfig : DbConfiguration
{
public CodeConfig()
{
this.SetProviderServices("System.Data.SqlClient",
System.Data.Entity.SqlServer.SqlProviderServices.Instance);
}
}
but where do I put 192.111.111.111\sql_box
every time I run Update-Database in the package manager I get
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
In the web.config or in the app.config.
<configuration>
<connectionStrings>
<add name="YOURDBCONTEXTNAME" connectionString="data source=SERVER;initial catalog=DATABASE;Integrated Security=false;persist security info=True;user id=USER;password=PASSWORD;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
Your connection string needs to be in the web/app config file in the startup project.
The connection string in the class library (assuming it is not the startup project) is used when making model changes, migrations, etc.
I'm just starting to learn C# and Entity Framework 6 ... and it's already far worse than I expected.
I have created a simple new project, and added EF6, while creating to database with Update-Database, I get:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
I haven't changed any config or anything, just created some classed and wanted to generate the database, here is the default connection factory:
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="MSSQLLocalDB" />
</parameters>
</defaultConnectionFactory>
I even checked if the instance is running by running this command:
sqllocaldb info
which resulted in:
MSSQLLocalDB
ProjectsV13
and same for this:
SqlLocalDB.exe start
LocalDB instance "MSSQLLocalDB" started.
I have even tried to disable the firewall ... but nothing.
EDIT:
App.config:
<?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>
<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" />
</providers>
</entityFramework>
</configuration>
after i saw your project you just need change the app.config connectionStrings
<connectionStrings>
<add name="masterEntities"
connectionString="data source=(localdb)\MSSQLLocalDB;initial catalog=master;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework;"
providerName="System.Data.SqlClient" /></connectionStrings>
i have made a WPF application which works fine on windows7 and XP. However, after adding some functionality related to databases and entity framework it still runs under windows 7 but not on windows XP.
Every time it tries to use the database i get a "Operation is not supported on this platform".
I have added all the dlls needed and modified the .config as you can see so the app can run without sql server CE 4.0 installed.
I have tried installing sql CE on the windows xp machine as well and edit the .config to use it instead of the dlls, but i get same result.
More info: The app is made to run on .net framework 4.0
Should i try another embedded DB?
<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=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<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>
<connectionStrings>
<add name="Conexion" connectionString="Data Source=|DataDirectory|Database.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
Ok i found the problem. Seems like sql server CE 4.0 needs windows XP SP3, and the test machine only had SP2, shame on me!
Server Error in '/' Application.
I have just started to publish the app to IIS server but it is failing, any ideas on this how to solve?
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. (C:\PBM_Test\web.config line 15)
Source Error:
Line 13:
Line 14:
Line 15: Line 16:
Line 17:
Source File: C:\PBM_Test\web.config Line: 15
this is the web.config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, `enter code here`System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</modules>
<validation validateIntegratedModeConfiguration
="false" />
</system.webServer>
<system.web>
<httpModules>
<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</httpModules>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<connectionStrings>
<add name="PBMEntities" connectionString="metadata=res://*/ModelPBM.csdl|res://*/ModelPBM.ssdl|res://*/ModelPBM.msl;provider=System.Data.SqlClient;provider connection string="data source=SRVORDERS;initial catalog=PBM;user id=OK;password=OK1;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
see http://forums.silverlight.net/t/180719.aspx/1
and http://community.discountasp.net/showthread.php?t=10296 for info
The above threads describe how you have to make sure that your web application has a copy of this file available.
If you are using a server you can install software to, the best solution is to make sure that the server has both the latest version of .net and RIA services installed (Both may be separate installations) (EDIT - make sure all the packages that alfonso list are installed.)
If you don't have access to install software on the server, the other solution is to make sure that ServiceMode.DomainServices.Hosting 4.0 is copied to the BIN folder during deployment of your ASP solution - set the file properties to Local Copy / Only if Newer
Make sure you have installed all of these packages on the server:
Silverlight4 Tools
Silverlight SDK
RiaServicesToolkit
RiaServices
Hope it helps!
I have a problem where I compiled my application on Visual Studio 2010 while targetting the .NET Framework 3.5, deployed it to a client server, only to find it gives me the following error:
************** Exception Text **************
System.MissingMethodException: Method not found: 'Void
System.Xml.Xsl.XslCompiledTransform.Transform(
System.Xml.XPath.IXPathNavigable,
System.Xml.Xsl.XsltArgumentList,
System.Xml.XmlWriter,
System.Xml.XmlResolver)'.
************** Loaded Assemblies **************
[...]
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
The method it says it's looking for is this: XslTransform.Transform Method (IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver) (Supported in: 4, 3.5, 3.0, 2.0, 1.1)
I've tried setting up a redirect to the .NET Framework 4.0 version of the same DLL using the assemblyBinding element like so:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Xml"
publicKeyToken="b77a5c561934e089"
culture="neutral" />
<bindingRedirect oldVersion="2.0.0.0"
newVersion="4.0.0.0"/>
<codeBase version="4.0.0.0"
href="file:///C:/WINDOWS/Microsoft.NET/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
But now the application won't run, and puts this in the event log:
EventType clr20r3, P1
myapplication.exe, P2 3.85.12.27583,
P3 4be9757f, P4 system.configuration,
P5 2.0.0.0, P6 4889de74, P7 1a6, P8
136, P9
ioibmurhynrxkw0zxkyrvfn0boyyufow, P10
NIL.
So, in summary, (1) does anyone know why the application can't find the method listed, and (2) why doesn't it let me redirect to the .NET 4.0 version of System.Xml?
Any help is appreciated, I'm totally stuck!
app.config as requested:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="myapplication.Properties.UserSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<system.net>
<mailSettings>
<smtp from="e-monitoring#myapplication.co.uk">
<network defaultCredentials="true" host="192.168.0.132" port="25" password="" userName="" />
</smtp>
</mailSettings>
</system.net>
<appSettings file="">
<add key="ReportDataCollectionTimeout" value="360" />
<add key="AllowedDatabaseBuild" value="3" />
<add key="AllowedDatabaseRevision" value="085" />
<add key="HelpNamespace" value="myapplicationHelpfile.chm" />
<add key="ProFormaHomePageUri" value="https://myapplication.co.uk/" />
<add key="ProFormaLoginPageUri" value="https://myapplication.co.uk/login.aspx" />
</appSettings>
<connectionStrings configSource="connectionStrings.config" />
<userSettings>
<myapplication.Properties.UserSettings>
<setting name="RequiresUpgrade" serializeAs="String">
<value>True</value>
</setting>
</myapplication.Properties.UserSettings>
</userSettings>
</configuration>
If you are targeting .NET 3.5 why are you doing a binding redirect to System.Xml v4.0.0.0? Make sure that your project references v2.0.0.0 of that assembly and that you have the following in your app.config:
<startup><supportedRuntime version="v2.0.50727"/></startup>
Also make sure that you are targeting .NET Framework 3.5 and not .NET Framework 3.5 Client Profile. Finally make sure the client has .NET 3.5 installed.
I've solved the problem by using this Transform method instead of the previous one (where I was previously passing null into the XmlResolver argument at the end).
Strange how this worked on my development and test machine, and not the server.
Try looking into the file version for System.XML.dll in the assembly folder. chances are that the last bit of the file on your system are different then the ones on server. in your case "2.0.50727.3082" does not seem to have the specified method signature. The version on the development machine was "2.0.50727.8009" which did have the required method signature.
EDIT: Decided to use the XMLReader version of the method. Even though we could register the newer version in the GAC(which did'nt give runtime error) from our local machine and that removed the error. but since the .NET could upgrade to a newer version and overwrite GAC we would need to be careful that the newer version would not have same problem.