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

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

Related

DocumentFormat.OpenXml.dll Not Working on Windows server 2008 R2

In my C# asp.net web application, used DocumentFormat.OpenXml.Dll to work with Excel file generation, it is working in one application server, but failed in another server, what would be the reason for it. How to check it?

How to Create connection on visual Studio 2008 Ado.Net Entity Data Model to Sql Server 2012

I want to create connection from visual studio 2008 to sql server 2012 by Ado.Net Entity data model,but I got this error at this photo support error
I tried to find a solution to this problem and I thought maybe OLEDB can be a solution but in this photo I want to choose .Net Framework Data Provider for OLEDB below to solve the problem by OLEDB but there is no selection of it. no selection of OLEDB
So please can you tell me how can I make connection vs2008 through ado.net or how I can select OLEDB because I need a web service to my smart device application. Because it is a smart device application I can only use VS2008 to develop. I am looking forward to hear from you. Thanks in advance.
You can develop the web service using any newer VS version, it is not tied to the Smart Device application in any way.

Way to use Entity Framework with Classic Asp

In my company, we have almost all the systems running on classic asp with the logic layer in dlls made by vb6. We use sql server and it's used via stored procedures.
Recently I found how easy is to connect to a procedure using entity framework, and we are trying to avoid the usage of vb6, and for tests purposes, i create a project in .net similar to the ones we use in vb6 with entity framework connecting to the procedure, and generating the tbl and using regAsm to register the dll, I could use it in the classic asp, but when i try to access the method that access the procedure, it gives me the return:
No connection string named 'xEntities' could be found in the application config file.
Where xEntities is the name of my context.
We can't migrate everything to the asp.net because of the time, but it will be very good if we stop using vb6.
Any suggestions?
Thanks.
Have you tried creating a web.config file with the appropriate Entity Framework sections in your web site folder? It is possible to have a web.config in a folder with an ASP Classic web site.

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

Entity Framework 4 CTP 5 POCO - Using an existing but empty SQL database on hosting environment?

I'm using EF 4 CTP 5 with an MVC 3 application, everything is working fine on my local machine, where EF 4 just create or drop the SQL CE whenever it needs to, since I have set the option to DropCreateDatabaseIfModelChanges. But I'm now trying to deploy my mvc application to a hosting environment, where I've created the database already, but the database is empty. It seems like the code can't drop, and recreate the database on my hosting environment, how should I solve this problem?
Update:
Here's the connection string to SQLEXPRESS:
<add name="KennySax"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
database=KennySax;
AttachDBFilename=|DataDirectory|KennySax.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
Thanks.
One other option is to use Joachim Lykke Andersen's DontDropDbJustCreateTablesIfModelChanged database initializer
It deletes and re-creates the tables if the model changes
He even has a NuGet package for it
Usually your running application in hosting environment doesn't have permissinons to modify DB structure. So you can run your application in your own environment and use Management studio to connect to SQL CE. Then generate SQL script from your DB and manually run that script in hosted environment. I hope it works with SQL CE - it will definitely work with SQL Express.
Well I'm not sure what I did, seems like a restart of the machine solved the problem. I was able to have SQLEXPRESS create the database and run the script on the hosting server. Thanks.