Mvc5 database SQL, VS 2013 - asp.net-mvc-5

I need your help, I am doing Mvc project in VS 2013 with SQL database, I have created database first and then I complete my project, but now working on project I change data type of one column, and the run project, it gives this kind of error.

By "database first", I'm assuming you mean your using EDMX. The EDMX is a snapshot of your database at the moment is was generated. If you change something in your database, you have to regenerate the EDMX.

Related

ASP.NET Core 2.0 Code First Migration - New Database

I currently have an ASP.NET Core 2.0 project and I've just implemented code first migrations to the localdb and have around 3 migrations including the initial create. I'm wondering what the correct process is to change to a new database? Is it simply a case of updating the connection string and running the below in the project directory?
dotnet ef database update
My current knowledge is based on the below Microsoft tutorial and I've been using the CLI commands.
https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/migrations
In answer to my own question, it does appear that running the following command in the existing project directory will build a new database from scratch including all the existing migrations. As long as you update the connection string to the new database and have already implemented migrations on the existing database.
dotnet ef database update
correct process is to change to a new database
Everything depends what you mean by writing this sentence ( I am not sure what "new database" means in it) altough flow looks like this:
1. First you make initial create
2. Then you change something in your code (create some additional fields etc)
3. Then you write "dotnet ef database update" command in CLI to update your current database.

How do you tell entity framework to create / deploy a database in Azure?

I'm using Entity Framework with a code first model; I've got my InitialCreate migration setup and working locally, I can run code against my database context, and everything works.
But when I deploy my project to Azure, I just get a connection string error ("Format of the initialization string does not conform to specification starting at index 0.").
I can't seem to find where in the Publish dialog are the options to create the Azure database. -- Do I have to create the database separately and hook them up manually? -- If so, what exact process should I follow. Does the database need to have contents?
I thought Microsoft was making a big deal that this could all be done in a single deploy step, but that doesn't seem to be the case from my current experience.
When you publish your project in the publish dialog, there is an option for the code first migration in the Settings tab, it will automatically show your data context and it will give you the option to set the remote connection string, and this will add a section in web.config to specify the data context and the Migration class to run during the migration process.
It will also allow you to set if you want to run the code first Migration or not.
You can also take a backup from the dev and clear the data then upload it to Azure SQL DB, this way the code first data context will check at first connection and it will find the code an database the same

LocalDB Export to Excel

I have collected a bunch of data using my locally developed website. Now I need to analyze the data, but it seems like I cannot locate the .mdf file for the LocalDB database my website uses.
Looking at the data connection, it says myusername\localdb#abunchofnonsense.mydomainname.Models.UserDBContext.dbo. And the the connection string is data source=(localdb)\v11.0; initial catalog=mydomain.models.userdbcontext; integrated security=true.
Also, I'm using ASP.NET MVC, Visual Studio 2013, and Entity Framework if it helps.
It's probably quite confusing what I'm trying to do here. I collected some data and need to run logistic regression with it. Now the question is how can I connect Excel to this LocalDB so I can export the data I have collected?
You can import your LocalDB tables and data directly into Excel by the option Get External Data > From Other Sources under the Data tab in Microsoft Excel (2013 to be precise) - as the following screenshot shows:
A bit late, but perhaps someone can use the answer as I found this thread when running into a similar problem:
The problem is, that the localdb uses a different provider than the "normal" SQL-Connection. You need to use the "SQL Server Native Client" (in your case version 11) to connect. The provider should be installed with the localdb - if not you can find it here
To use in Excel, just choose
"From Other Sources"
- "From Data Connection Wizard"
- "Other Advanced"
- Choose your provider
- Enter the rest of your connection details
(not tested, but I see no reason why it shouldn't work): For existing connections you can edit the connection string and add/change "Provider=SQLNCLI11.1" (of course considering your installed version)
Source: I had the same problem in Installshield where you have to change the provider manually, so I just tried in Excel.

How to combine Entity Framework and SQL Compact in Visual Studio 2012?

I am using the MS Entity Framework and Visual Studio 2012 in combination with the SQL Server Express. Now I want to use the EF in combination with an SQL Server Compact Edition database.
The design process will be model first.
I created an SQL CE database file in VS and started the design with a database model. I can create the .slqce file, containing the database schema definitions without any problems.
Actually my Problem is, that I can't find out how to execute this file on the database.
To test another approach, I created the database tables, columns... in the Server Explorer and used this to create an entity model. This worked well, but again, I don't know how to update the DB with changes, made inside the model.
What am I missing here?
You can use my SQL Server Compact Toolbox addin to create the database file and execute the script. You may need a modified template, as I describe here http://erikej.blogspot.dk/2013/02/fixing-entity-framework-designer.html

Visual Studio 2012 SQL Database Project with SSDT

I'm starting to use Visual Studio 2012 with integrated SQL Server Data Tools and although I watched 2 of microsoft's video's on getting started with SQL Database Projects I'm still having trouble understanding how to work with them especially since I'm new to db development.
Some questions:
What is the difference between Importing a database or adding a reference to the database?
What is the difference between Server Explorer and SQL Server Object Explorer tabs? In one I can browse the database through localhost\SQLEXPRESS.dbname and the other goes through localdb\Projects. At what point are these synchronized?
How do I change the Target Database Name under the Project's properties?
1) Importing a data base creates a project that includes all of the databases artifacts. Adding a database as a reference allows a project to access the database. So if you have a SSDT project and a c# project that uses the db, the c# project gets the reference. You could choose to create the SSDT project by importing an existing db.
2) SQL Server Object Explorer is part of SSDT and allows you do perform online SQL development including creating new artifacts, adding data to tables, and executing scripts.
3) To change the target database name for debugging purposed (where the database goes when you build/debug) change the target connection string in the debug tab of the properties menu of the project.
I've found this link to be quite helpful.
There are many differences between SQL Server Object Explorer (SSOX) and Server Explorer. Here's a couple:
SSOX allows you to launch refactoring operations
SSOX provides a logical view of your source code in Solution Explorer
In short, SSOX targets database development whereas Server Explorer is (I think) a generic hierarchical viewer for many server types.
Regards
Jamiet

Resources