I'm developing a WPF that generates an SQLCE DB at runtime and fills it.
Everything runs fine in debug, but when I distribute an app to a 64bit Windows 7 machine I get a
Access to the database file is not allowed
error because the system cannot create the .sdf file. I think it's a permission issue but I don't know what I can do to avoid this problem, is there anything to do in setup project or a flag to give to Entity Framework for forcing DB creation?
Create the sdf file in a location where the user has write access.
Related
I mean, for example, installing a database using a webserver then deploy the database with my application without more configuration, just a portable database, is it possible? Currently my mongo database is installed and dependent of my computer system, I would make it portable, it is possible to build a database upon my webserver, hence make it portable?
Any hint would be great,
thanks
I am trying to build a basic web app, and I want to connect it to a database. I have a heroku account so I started trying to get it hooked up to a Postgres DB and ran into issues around SSL and external connections. I tried to update my code and realized that I was missing the references to SQL so tried adding Entity Framework through the package manager.
It goes through the checking compatibility and then tells me
Could not add Entity Framework
I am new to this so not sure what I can provide to help get the answer.
Am I just going about it wrong, is EF not what I need to make a simple DB connection?
I have two projects which are targeting the same database. One of them is an MVC web application and the other is a Web API project. However, when I initialize an instance of the context in any of the projects I get the following exception:
Cannot attach the file 'myRoute/MyDatabase.mdf' as database
'MyDatabase'.
They way I have solved this is by:
Erasing my database from the SQL server object explorer (as stated in EF5: Cannot attach the file ‘{0}' as database '{1}')
Running code first migrations once again.
However, if I run the code first update while my startup project is the web application, the web services generate the same exception. If I run the code first update while my startup project is the web service, then the web application has the same issue.
What happens?
For what its worth I had this problem and apparently solved it by adding an explicit reference to the database in the MVC Web.config file EXCLUDING the AttachDbFilename clause:
I have a web application which uses:
MVC3, Razor, C#, EF4.1, .NET4, MSSQL2008(local), SQL Azure(Cloud)
It reads data from DB, merges it and create an XHTML document.
When run locally(IIS Express/VS2012/Win7), it is fine.
When run locally in Emulator, also fine.
When run in WAWS, very speedy.
I am running .NET 4.0 in the cloud service, WAWS runs .NET4.5, this could be significant???
I have seen reference to compiled EF being great in performance. How do I compile my EF? I have a seperate EF Model Project for my DB access code which is compiled as a DLL into my Web Application bin folder.
EF performance issue, See:EF Performance Article
I have run the profiler in sample mode on my cloud service, and the LINQ/Entity lines seem to be the "Hot" commands, so it is EF related.
I would appreciate your comment on this please.
Thanks in advance.
P.s Now off to recompile my app in .NET4.5, and redeploy.
EDIT
Just redeployed using osFamily="4" and .Net4.5 and processing time reduced from 30 secs to 1 secs !!!!! Amazing. In runtime after deployment was still about 30 secs.
EDIT2
After change to .NET4.5 I got lots of "invalid Access to memory location" errors when invoking the full emulator. Not sure if this is to do with me running VS2012 or WIn7 with osFamily="4" in the emulator. see: Solution
I guess I should have thought of this before I started my project but I have successfully built and tested a mini application using the code-first approach and I am ready to deploy it to a production web server.
I have moved the folder to my staging server and everything works well. I am just curious if there is a suggested deployment strategy?
If I make a change to the application I don't want to lose all the data if the application is restarted.
Should I just generate the DB scripts from the code-first project and then move it to my server that way?
Any tips and guide links would be useful.
Thanks.
Actually database initializer is only for development. Deploying such code to production is the best way to get some troubles. Code-first currently doesn't have any approach for database evolution so you must manually build change scripts to your database after new version. The easiest approach is using Database tools in VS Studio 2010 Premium and Ultimate. If you will have a database with the old schema and a database with the new schema and VS will prepare change script for you.
Here are the steps I follow.
Comment out any Initialization strategy I'm using.
Generate the database scripts for schema + data for all the tables EXCEPT the EdmMetadata table and run them on the web server. (Of course, if it's a production server, BE CAREFUL about this step. In my case, during development, the data in production and development are identical.)
Commit my solution to subversion which then triggers TeamCity to build, test, and deploy to the web server (of course, you will have your own method for this step, but somehow deploy the website to the web server).
You're all done!
The Initializer and the EdmMetadata tables are needed for development only.