SQL server CE 4.0 windows XP - wpf

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!

Related

SQL connection string from ASP.NET app does not work in WPF

Several ASP.NET applications are running on the server of our company.
Connections strings in web.config look like this:
<add name="somename"
connectionString="Data Source=SERVER\INSTANCE; Initial Catalog=DbName;User Id=user; Password=*******; MultipleActiveResultSets=True; Integrated Security=true"
providerName="System.Data.SqlClient"/>
and work perfectly with no errors.
But when I copy this connection string from web.config to app.config of my WPF app, I get the following errors:
Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
Or (if I remove Integrated Security from string)
Login failed for user 'username'.
Also I cannot log in via SQL Server Management Studio (causes the same errors).
My app.config looks like this:
<?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>
<connectionStrings>
<add name="somename"
connectionString="Data Source=SERVER\Instance;Initial Catalog=DbName; User Id=user;Password=******;MultipleActiveResultSets=True;Integrated Security=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>
Both username and password are 100% correct, SQL Server uses mixed authentication.
Managed to log in with sa login of SQL Server
Edit the registry using regedit. (Start –> Run > Regedit )
Navigate to: HKLM\System\CurrentControlSet\Control\LSA
Add a DWORD value called “DisableLoopbackCheck”
Set this value to 1

Change connection string in Entity Framework from localDB to Microsoft SQL Server

I'm trying to use SQL Server 2016 instead of localdb. When I try to change it in the web.config file from mssqllocaldb to v13.0
it gives me the following error:
An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user code.
Additional information: 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
You can read about the configuration at MSDN: Entity Framework Config File Settings
An example web.config could be:
<?xml version="1.0"?>
<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="MyConnectionString" connectionString="Data Source=MySqlServerInstance;Initial Catalog=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<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>

Visual Studio 2015 cannot connect to SQL Server LocalDB

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>

How do I not use the App_Data folder in an ASP MVC4 application?

Everything works fine locally, but when I publish, I get the error below. I am using forms authentication, but I define my own connection string to a non-sqlexpress database. I don't understand why my application would need access to create a database (or anything else) in the App_Data folder, because my database is not/will not be there. Any help is appreciated.
Connection String:
<connectionStrings>
<add name="DataContext" providerName="System.Data.SqlClient" connectionString="Data Source=localhost;Initial Catalog={my db};Integrated Security=SSPI;MultipleActiveResultSets=True" />
</connectionStrings>
Error:
Access denied creating App_Data subdirectory
Description: For security reasons, the identity 'IIS APPPOOL\ASP.NET v4.0' (under which this web application is running), does not have permissions to create the App_Data subdirectory within the application root directory. ASP.NET stores the Microsoft SQL Express Database file used for services such as Membership and Profile in the App_Data subdirectory of your application.
Edit: It tells me how to fix the error by adding the App_Data folder and providing the correct permissions, but I don't understand why I need this folder at all, and if I can avoid changing permissions, I'd like to.
I think I finally figured out how to stop ASP from trying to create the ASPNETDB.MDF database in the App_Data folder automatically. What I found worked combined two existing stackoverflow answers:
Disable SQL Membership Provider (ASP.Net Forms Authentication)
It turns out that, on the production machine, the SQL membership provider was defined in machine.config. I don't think the ops team changed anything from the default Windows 2008 install, so that's probably generally the case for that platform.
To remove references to any SQL providers defined at a higher level include the following in your web.config
<membership>
<providers>
<clear />
</providers>
</membership>
<roleManager enabled="false">
<providers>
<clear />
</providers>
</roleManager>
<profile>
<providers>
<clear />
</providers>
</profile>
AspNet Role provider kicking in and it shouldn't be
To disable 'SimpleMembership' you can add app setting enableSimpleMembership with value="false" (web.config). This will prevent webmatrix from reconfiguring RoleManager.
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="enableSimpleMembership" value="false" />
</appSettings>
</configuration>
Check if the 'connectionStringName' property of the 'membership' node in your web.config is set to your connectionstring, like this:
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider"
type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="DataContext"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
*<membership>
<providers>
<clear />
</providers>
</membership>
<roleManager enabled="false">
<providers>
<clear />
</providers>
</roleManager>
<profile>
<providers>
<clear />
</providers>
</profile>*

Entity Framework on SQL Server CE without driver install

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 ;)

Resources