Publishing an MVC application using SQL Server Compact Edition to IIS - entity-framework

I'm attempting to publish an MVC web application to a locally running instance of IIS using Visual Studio 2012. For the database, I'm running SQL Server Compact Edition and my connection string in the web.config looks like this:
<connectionStrings>
<add name="OpserveEntities" connectionString="Data Source=|DataDirectory|Opserve.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
When I follow through the Publish wizard, under Settings/Databases I'm entering Data Source=|DataDirectory|Opserve.sdf. When I attempt to publish I get the following error message:
Unable to complete operation. The supplied SqlConnection does not specify an initial catalog or AttachDBFileName.
However, the application runs as expected when running/debugging in Visual Studio.
How can I resolve this and get my application published and working?

Related

How to create IIS-website from powershell in order to host .net core 2.0 app, error 0x8007000d

Expected Result:
IIS hosts my app correctly, and when I navigate to the url of my app (e.g: blabla/swagger) I see the swagger UI describing my app
Problem:
When I try to navigate to my app it says:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Information
I built an app in .net core 2.0 and I am able to make it run through visual studio, being hosted by Kestrel.
However I need to deploy this app to different servers and since Kestrel doesn't support host names, I need to make it being hosted in IIS . When I make it run through Kestrel I am able to access it correctly and by navigating to the url/swagger address, I am able to see the correct swagger page that describes the app.
My app is being published from visual studio. Which means in its published folder there are all the dlls that the app needs. It's being published as a framework dependent app, not a standalone one, but this shouldn't matter.
How to replicate the problem
Since I need this one day to be hosted in IIS inside a Docker container, I am trying to make it being hosted in IIS with powershell scripts. What I did to make it being hosted in IIS is:
New-Website -Name 'myTestApp' -force -Port 8080 -PhysicalPath
'C:\Users\myUser\Desktop\Docker\PublishOutput' -ApplicationPool 'MyAppPoolTest'
Where C:\Users\myUser\Desktop\Docker\PublishOutput is the path to the published folder where Visual Studio publishes the app. Thanks in advance!
This is the web.config generated by Visual studio when publishing:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\Friss.CaseApi.Web.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: 313d542d-7676-4440-ae1b-22c6071f4309-->
And the error page is:
Am I setting the web.config in the wrong way?
Check the documentation here
You need to publish your website and then point IIS website to the published folder
Application pool must be set to No Managed code
Application Pool identity user IIS AppPool\{AppPoolName} must have read permissions on the published website folder
Found the solution,
the system requires the dotnet core windows hosting bundle. The bundle installs the .NET Core Runtime, .NET Core Library, and the ASP.NET Core Module.
Documentation: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.1&tabs=aspnetcore2x
Direct download to the bundle for .netcore 2.0.6 that solved my problem:https://download.microsoft.com/download/8/D/A/8DA04DA7-565B-4372-BBCE-D44C7809A467/DotNetCore.2.0.6-1-WindowsHosting.exe

Entity Framework: Setting correct connection string to SQL Server Compact in ASP.NET MVC 4

I want to use and embedded SQL Server Compact edition in my asp.net mvc 4 project. I try to approaches but I have problems with any approach:
First attempt
I have created a new data connection from visual studio and from server explorer of type Microsoft SQL Server Compact 3.5 and I store the .sdf file in my asp.net mvc 4 project under \App_Data folder (I add this .sdf file to this folder). I guess doing this I create and embedded SQL Server Compact database for my web application, am I right?
Finally, I create the following connection string in web.config:
<add name="DefaultConnection"
providerName="System.Data.SqlServerCe.3.5"
connectionString="Data Source=|DataDirectory|\App_Data\MyDatabaseSQLCe.sdf" />
I start my web application but an error occurs, database seems to be not found, well the error says something like:
SQL Server Compact is not intended for asp.net development
I am not sure if the connection string above described is the correct.
Second attempt
Also I have downloaded the SQL Server Compact 4.0 from here:
http://www.microsoft.com/en-us/sqlserver/editions/2012-editions/compact.aspx
and I have installed. Once installed If I go to create a data connection as above described it does not appears SQL Server Compact 4.0 from Visual Studio. I would like to use an embedded SQL Server Compact in my project but I am completely lost.
Conclusion: my goal is to use SQL Server Compact edition as embedded in my asp.net mvc 4 web application and put this .sdf file in my \App_Data folder and make it works with the correct string connection in web.config.
|DataDirectory|\App_Data yields App_Data\App_Data, if I am not incorrect. Try Data Source=|DataDirectory|\MyDatabaseSQLCe.sdf.
You can test this by dumping AppDomain.CurrentDomain.GetData("DataDirectory").ToString() on your webpage.
You should grab the toolkit for visual studio when dealing with Sql Server Compact.
http://visualstudiogallery.msdn.microsoft.com/0e313dfd-be80-4afb-b5e9-6e74d369f7a1

Entity Framework 5 always try to connect to sqlexpress instead of local db

I'm using Visual Studio Express for web to follow this tutorial http://msdn.microsoft.com/en-US/data/jj193542.
The tutorial tells that
By convention DbContext has created a database for you.
If a local SQL Express instance is available (installed by default
with Visual Studio 2010) then Code First has created the database on
that instance If SQL Express isn’t available then Code First will try
and use LocalDb (installed by default with Visual Studio 2012) The
database is named after the fully qualified name of the derived
context, in our case that is
CodeFirstNewDatabaseSample.BloggingContext
So, it should use localdb. But when I try to access my model, I can see in debug that the connection string points to .\SQLEXPRESS, althought I don't have sqlexpress. So, I got a timeout exception ...
Why localdb isn't used ?
Note that if I set explicitly the connectionstring to localdb, it's working ...
Note too, that if I use Vs Express for Desktop, it's working too...
What's wrong with the Vs Express for web ?
EF Connections explained
Tell EF the factory to use by default, eg
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>

EntityFramework deployment with AppHarbor

I am running into a strange problem after deploying my site to AppHarbor.
I always get this error :
Exception Details: System.Data.MetadataException: Schema specified is not valid
It is clearly linked with my connection string (which works perfectly on my dev machine)
<add name="DbEntities" connectionString="metadata=res://*/Models.DbModel.csdl|res://*/Models.DbModel.ssdl|res://*/Models.DbModel.msl;provider=System.Data.SqlClient;provider connection string="Server=xxx.sqlserver.sequelizer.com;Database=xxx;User ID=xxx;Password=xxx;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I dont use EF code first so I cannot remove the metadata section.
Any idea what to do to fix it ? I couldnt find anything to help me get over this...
For Info I am using VS 2012, .Net 4.0, EF 4.4
The AppHarbor knowledge base has info on using the SQL Server add-on, including setting the metadata-string: http://support.appharbor.com/kb/add-ons/using-sequelizer

Azure error when using EF agains SQL Server CE 4.0 database

I have an ASP.NET MVC 3 application which I want to deploy to Azure. The application uses EF against a SQL Server CE 4.0 database in the App_Data directory.
The site runs fine locally but when I reference it from an ASP.NET MVC 3 web role and publish it to Azure I get this error:
"Unable to find the requested .Net Framework Data Provider. It may not be installed."
The full exception can be viewed here: http://52df5a4a5c1b4d10a927078bb8a06d15.cloudapp.net/drug
Here is connection string from the web.config file:
<add name="DbEntities" connectionString="metadata=res://*/AMDBModeledmx.csdl|res://*/AMDBModeledmx.ssdl|res://*/AMDBModeledmx.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=|DataDirectory|\AMDB.sdf"" providerName="System.Data.EntityClient" />
I have tried compiling my project to target x86 and setting the "Copy Local" property of the System.Data.Entity reference to true. Nothing helps.
Is it possible to run a web app in Azure and use a file-based database? I understand this can be a problem with multiple instances, but I'm only using a single VM.
I can't see your error page, but it looks like the SQL CE Data Provider DLL is missing. Have you tried following these instructions?
http://blogs.msdn.com/b/webdevtools/archive/2011/01/06/how-to-bin-deploy-sql-compact-edition-4-0-and-razor-web-projects.aspx