How to Link SQL Server Express to MVC - asp.net-mvc

Aimed to link my pages to an existing db from SQL Server Express. There are only one table is gonna select. Followed NerdDinner tutorial, using LINQ-to-SQL designer to do this.
However the result does not overcome what it suppose, my table Dinner can not be called directly, what would be the mistake I make?
The result return *.dbml and NerdDinner with *.edmx. What are their different?

You must set your connection string to store database in sql server express.Note that the *.edmx database type will store in local file system maybe at App-Data folder in your project as a database object. but another type, say, *.dbml is for using at DBMS system ,here SQL server Express. Also you can convert the *.edmx type to *.dbml type via SQL server tool.
Look at your web.config file at root of project.At the configurations, you will see that the connection string is setted to store at local file system of type .edmx. try to change it.

Related

Umbraco - Installation & database

I've begin the development of my Umbraco Website. I've forgot to include a database on the setup so I think that all my stuff is in the cache. Am I right ?
However, I've tried to include a connection string, all is fine, Umbraco can connect to my database, but now Umbraco is looping on the Installation page and do nothing.
My database is empty and on any url Umbraco is trying to install.
I'm using Umbraco 7.6.3
How can i add my database so all the stuff I've made is not lost ?
Thanks !
Alex,
when you use the default settings during installation of Umbraco, then it wil use SQL CE.
This method will save all data not in SQL server but in a local sdf file which is located in the App_Data folder.
If you want to change this, then the best way will be to start over the entire installation incase you haven't add any elements to your existing version.
Then during installation you can choose to specify other options for the database, like adding the database to your Sql Server instance.
If you want to convert your existing SQL CE database to sql server, have a look here:
https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/53818-Convert-Umbraco-SQL-CE-database-to-SQL-Express

Entity Framework creating settings table that I can't put on Azure

I've been trying to create an ASP.net - MVC app that uses entity framework to connect to an Azure database.
I used a database first method to try and create the Model, I was able to connect to my azure database and successfully create the model.
Everything was working perfectly and I was able to retrieve my values from my azure database then I tried to publish the website to an Azure website. The website works fine and I have the website registered as able to use the azure database. When I click on the button that hits the controller to access the database I then get "Sorry, an error occurred while processing your request."
When I looked into this a bit more I seen that when I created my Entity Data model using the wizard it created a connection string to a local db for my entity connection settings. I'm guessing this is saving some entity framework settings but my problem is obviously when I publish the website to Azure it can't access this local db.
Any suggestions on how to either get this DB onto Azure or avoid using this extra database?
Thanks
This is the best tool to migrate your local database to Azure. Before publishing your site change the web.config to point to the Azure database. It will solve your problem.
Like you already explained, it seems that you web.config still points to your local database. Try to look at your web.config and see if you have connection strings pointing to .\SQLExpress, localhost\SQLExpress, ".", ...
Then, like Geenthanga's explains, you need to modify this value before deploying (it should point to your SQL Azure database instead). But you shouldn't do this manually! Instead, consider using web.config transformations, as explained here: Web Deployment: Web.Config Transformation.
This way you can have 2 web.config transformation files:
Web.Debug.config: This file would contain the transformations to add the connection string pointing to your local database.
Web.Release.config: This file would contain the transformations to add the connection string pointing to SQL Azure.

mvc ef code first database creation map

was wondering if it's possible to point the visual web express to a specific folder when it builds the database using entity framework code first. this question stemmed from this one:
mvc connection string code first
anyway, i was able to successfully build the dbase using code first but sql server management studio is looking at a diff folder. is it possible to piont the web express to that folder when creating the database or is it better to just point the sql server management studio to where it's building it to? (does that make sense?) i tried fiddling with the ssms properties but it still won't look at that folder..
It whole depends on the connection string. If you are using default connection string for web application it always creates database in App_Data folder - it is specified by AttachDbFilename=|DataDirectory|DatabaseFileName.mdf. Using this is recommended way if you want your web app to create database because it should have necessary privileges by default.
If you want to place the database "elsewhere" you should not use attached db file and instead let SQL server create database in its default location by calling omitting AttachDbFilename part of the connection string. This can require additional security configuration to allow web application to create the database.

MVC 3 Adding a local Database

I am currently going through the MvcMusicSore tutorial (MVC 3). I have full sql server 2008 installed and created a local database by running the SqL scripts included in the MvcMusicStore-Assets data folder. However when trying to add the mdf to the AppFolder in Visual Studio 2010 I get the error Access Denied. I am completely stuck at this point and would appreciate any help to resolve this.
Most probably the mdf file is locked by some other process, not allowing the application to read it. If you mounted the database on SQL Server you need to use a connection string with the machine name instead of specifying the mdf file directly.
You can't copy or modify a live working database. And I don't see why you should.
You need connecting to it? Pick a way. LINQ to SQL, Entity Framework, NHibernate, ADO.NET...
If you really want to copy the database file for some reason, you must first stop the MSSQL Service (or detach the database), then do that.
Like others have said, you shouldn't need to add the actual .mdf into your project. If you have it running on your local SQL Server instance, you should be able to add it via Visual Studio's Server Explorer (plus that gets you your connection string).

When attaching a SQL Express DB via a connection string, is it an exclusive lock?

In .NET, you can open a SQL Express database simply by attaching the database MDF file in the connection string (that is, you don't have to have any server software installed, it just attaches to the MDF file on the fly).
When an application does this, does it obtain an exclusive lock on the database file? Or, can a second application also attach to and open the MDF file in this same way, and query the database while program #1 is using it?
You are correct, only a single connection can be open to the MDF at a time.
This can get really annoying when you open the database through your server explorer in Visual Studio, and then try to run your application.
I've caught myself doing that too many times to count, and I always invariably end up just attaching the mdf to my sql server instance.

Resources