SQL Server in App_Data MVC - sql-server

I just created a SQL Server Database in my App_Date by right clicking -> Add new Item -> SQL Server (Not compact).
I have created a model with the necessary data.
How do I go about sending data to that database? I don't mind using any method i.e. Linq/EF etc.

Best you open the sql server compact sdf file by double clicking it. Here you will be able to modify the database tables / columns etc.
Next add a new project item. Select Entity Framework database and go through the guided wizard.

Related

How can I update existing SQL datasources (Live) to connect to correct views (reconnect) in Tableau Deskop?

I have one question. I am new in Tableau and I have to update existing SQL datasources (Live datasources) to connect to correct views (reconnect) in Tableau Deskop, because of some mappings/new data that were added to SQL database.
For the same reasons, I have to also create new Tableau datasources.
How do I do that, update existing SQL datasources and create new datasources? Also, for creating new datasources is it possible to do it from Tableau Server or just from Tableau Desktop?
Thanks.
I believe Tableau only allows you to create data sources in the desktop environment.
If your SQL source is using a SQL statement you can alter your query to bring in the new data and then refresh the extract.
It's worth noting that the desktop extract is no longer used once you've published your workbook to the server (until you need to make more changes in the desktop environment).
I find making changes on Tableau server limited, so it's almost always best to make significant changes on desktop.
Also, if you're changing to new data sources, once you've loaded the data into Tableau, in the Sheet view you should be able to right click on one source and choose to point your views to the new source.
It all depends on the desired result.

How can two SQL databases be merged into one database?

I have 2 SQL Server databases. The reason is because I created an ASP.NET MVC project using "Individual User Accounts" for authentication. This created a default connection with a database that includes the following tables:
AspNetUserClaims, AspNetUserLogins, AspNetUsers, _MigrationHistory
I then went a step further and built out my own custom roles with a RoleController. So I also have a table for AspNetRoles and AspNetUserRoles. Everything with this is working.
I also have another database that I built in Management Studio that is holding all of the data of my application. I am using Entity Framework to communicate with the database.
I currently reference both databases in my web.config connection strings.
But I would like to migrate the database from the default connection (with my AspNetUsers) into the one in Management Studio.
Is it as simple as copying the tables and putting them in my other database in Management Studio or can I copy the whole schema? Just trying to figure out the best approach here.
You can migrate tables from a database to a diferent one. On SSMS, just right click on a database, select Tasks -> Generate Scripts, and use the wizard to create a script with the table definition and data (optional) to be executed on the new database.

MVC Membership database to SQL Server 2008

When I create a new MVC application with EF, it creates all the views, models, controllers and logic for users to be able to log in, change passwords etc. The data is held in a MDF file in the app_data directory.
I used this for my users, and then had my own SQL Server 2008 database which was created code first using EF for all my other tables. When I wanted to reference a user from a table within this database, I used the ApplicationUser.Id.
Doing it this way, I have not got a foreign key between the table that holds the users and any other table in my custom DB, but thats a different topic.
The question I have, is how I can I stop this happening every time I create a new application, and how do I fix the issue I have now.
I have two different databases, when I just need one. have one database in SQL Server (which is what I want) and one in a file which I cannot convert to SQL Server as it was created in 2012, and I am using 2008 SQL Server.
I am wanting to now deploy this on a server where all data is read from SQL Server.
The way I see it, I need to somehow get all the tables it creates for Membership, and put them into the database I created, then change the connection string. However first off I don't know how I would do this, and second... WHY do I have to do this? How can I just have one database next time. Am I missing something?
After some research and messing around, I have answered my own question and think it may be useful for others.
I am using MVC 5 with the default ASP.NET Identity for my users.
What I found is that if I changed the connection string to point to my SQL server, it will create the database for me (the one that was previously a file in my app directory).
I then added a connection string to the same database for the context I created and it created all the tables for that in the same database.
The result is that I have one database with all my tables in.

Create Database Instance from Model

*Seems like there is some confusion. I created a SQL Server Compact Edition file and can see it from the Server Explorer. I can also right click and add tables manually. What I want to do is run the generated sqlce file to add all of the tables and columns from my model to the SDF.
-- background --
In Visual Studio 2012 (Ultimate), I designed a model using the model designer. It created an edmx file. I right clicked the model and chose "Generate Database from Model..." and created an sqlce file. My understanding is that I should be able to execute this file on an sdf somehow to create a SQL Server Compact Edition Instance of my database. I don't see the option on right click to execute the sql code, and the other option is to "Run SQL Scripts in Solution Explorer" which doesn't seem to make sense.
http://msdn.microsoft.com/en-us/library/yea4bc1b.aspx It says to drag the sqlce file to a database reference, but I'm not really sure what they mean. I have tried to drag it to the server explorer where the sdf is connected.
I tried right clicking on the sdf in the Server Explorer to do New SQL Query and pasting the sqlce in, but it seems that Create Table isn't supported.
Any ideas?
Generate Database from Model... only generates tables and relationships.
You need to have a database created already, and have it in the Database References folder. Then you drag your script file to that database reference, as described in your mentioned link.

Insert rows in to SQL Server using Visual Studio's Server Explorer

I have created a Database in MS SQL and loaded the Database in my Server Explorer. In my MVC application, I wish to simply populate a single entity inside my database (Customer Name for example), does anyone know how I can send data to the database I have loaded? I can't seem to figure it out.
Any help will be highly appreciated.
If you're asking about how to insert data in Visual Studio itself, open Server Explorer, add a Data Connection to your database, expand the Tables node, right click on your table and select Show Table Data. This opens up a screen where you can add data.
If you only want to connect and populate one entity you should consider using Code First Entity Framework to drive your model using a plain C# class on the entity.
Scott Guthrie has a post on how to do that: Using EF Code First with an Existing Database, and Ralph Lavelle has a post that's more specific to MVC and includes migrations in the second part: Using Entity Framework Code First with an Existing Database (1/2) and Using Entity Framework Code First with an Existing Database (2/2).

Resources