MVC VS Template with Authorization: When is the database file created? - asp.net-mvc

The template comes without database at first. When I launch the application some code must create the db obviously, because I check the appData folder and now it's there.
Can you tell me which part of the code creates it? Thanks. I have long looked at the code and I cannot figure it out.

I think the only answer possible is that entity framework creates the database automatically. But the strange thing is if I remove thee database it does not get recreated, I get an error that says it's missing it.

Related

Database recreated everytime Application runs

Good day guys,
I noticed my application deletes database structure and re add new one everytime i Run my application.
The DBset uses DropCreateDatabaseIfModelChanges. I have read about the other options like CreateDatabaseIfNotExist. is there any other option to force it from recreating database?
And also with throwing any exception of error?
I have been able to resolve this by using Code First Migrations

Is there a way to changing Core Data schema without migration during early development?

At the early stages of development, where data retention is no issue and experimental changes to the schema are expected to be numerous, is there a way to avoid migration? Namely, just to dump the database and start over each time.
Everything I try leads to the error: "The model used to open the store is incompatible with the one used to create the store".
Lightweight migration looks do-able, but I'll end up lots of unwanted versions and messy code. I'd also like to experiment with relationships (no wise cracks), but understand I'd need to commit to a heavyweight migration afterwards!
If the solution is to check for the existence of the original database using NSFileManager and delete/remove it if found, could someone please show the swift code with an example name of the original database, and how it can be effectively removed.
I've been trying several suggested solutions, such as dragging a copy of the .xcdatamodeld file onto the desktop, deleting the file in xcode and bringing it back in, but I keep getting the error that the model and store are not the same.
Answered in one line in first comment, but appreciated in reverse proportion.

MVC3 Entity Connection string disappearing

I am having a very frustrating problem with my current project. It is continually losing the connection string binding for Entity models.
I have multiple models for different databases in separate areas and was having no problems. Suddenly now whenever I try to update from the database I get the connection string setup prompt. I select for it to add it to the Web.config with the password but it doesn't ever pick it up there again. They all are still in the web config but it just doesn't see them.
If I remove all the connection strings from the config file it will write the new one there. Then when I try to set up a Stored procedure/Function Import, I still get the statement in the lower box:
No database connection has been configured for this model.
I have tried rebuilding the project and creating the models again from scratch and that works for a while. When I try and bring the project in under Perforce source control, it winds up getting re-corrupted & the connection string goes away. It affects all of my models too.
I am also using EF 4.x DbContext Generator to create context files. They work fine. I am also able to run the application and it connects to the database just fine and returns data. No issues there. I am just unable to update Entity Complex types from the DB or import any more stored procedures.
An even weirder occurrence was that I opened a broken project from a different directory then opened an uncorrupted copy it instantly became broken also. Contagious!
Any thoughts on where to look into to see why this is happening? Has anyone else had this issue?
I seem to have found where the issue is coming from.
I seem to have a bad value somewhere in my web.config which causes the issue. Here is the work around I found did the trick and showed it's the config:
When the binding breaks, I closed the project then swapped out the web.config with one from a good build which was missing a couple keys but worked well enough to bind.
I reopen the the solution and the "No database connection..." error goes away.
Then while the solution is still open I re-swap the web.config back in and it still works.
This is far from optimal but I can work until I figure out the bad value via doing some compares.
I will comment on this again once I determine the exact issue.

MVC Code First Connection String. I changed it. How do I reinitialize the database?

I mean I was using a .SDF file but then had issues getting that to work with my host. So then I went back to the SQL DB I already have but I noticed that when I go to the default MVC 4 index page it is looking for that entity that I already created when I used the original DB.. but this table does not exist with the new SQL DB I switched to..
I already verified that is is pointing to the new DB buy setting the connection string in the constructer.
How do I tell the code to 'RE CREATE THE TABLE' before trying to use it ?
If I understand your question correctly, you're looking for something like Entity Framework Migrations: http://www.hanselman.com/blog/EntityFrameworkCodeFirstMigrationsAlphaNuGetPackageOfTheWeek10.aspx

Getting the SubSonic MVC Templates to work with my database

I downloaded and installed the SubSonic MVC templates. I'm able to create a new project from this template and the 'prewritten' views work fine. I'm able to edit records from the Artist table of the included 'Chinook' database.
So now I'd like to get this to work with MY database. Here's what I've done.
Changed to connectionstring in the Web.Config to point to my DB running on a local copy of SQL 2008.
Updated the _Settings.tt file to reflect the above connection
rerun the each of the tt files by right clicking and selecting 'run custom tool'
** when I do this all the cs files is are empty. No errors just empty files **
To be sure I've removed the Referance to SubSonic and readded it with no help.
Have I missed something? Can anyone tell me what I'm doing wrong?
The Error List should show what's happening when you try to run the custom tool and you get nothing. Do you see any errors listed there?
Do the tables in your database have Primary Keys? This is a required convention for SS ActiveRecord.
I finally got this to at least build with out errors. I had some database connectivity issues which were causing my initial problems, however after that I still could not build successfully. I was getting a bunch of referance errors. I had to change the code.
DataProvider.Tables.Add
had to be changed to
DataProvider.Schema.Tables.Add
in the Context.cs file
So for now it Builds but I haven't gone any further yet.
-MARK-

Resources