How to get an ASP.NET MVC 3.0 site to use a db other than the default SQLEXPRESS?

A couple things to look for In the ConnectionStrings element, you may try clearing any existing connection strings by way of clear before defining any other connection strings. This will clear any inherited connection strings that may be causing the problem Since you are using MVC3, I am going to assume that you are using Entity Framework? Ensure that either your DbContext (ef 4.1) or any other Context object is being properly configured to use "TestDB As for where the SQLExpress db is located, from the original connection string, it appears it is looking at your local SQLExpress server.

A couple things to look for... In the element, you may try clearing any existing connection strings, by way of , before defining any other connection strings. This will clear any inherited connection strings that may be causing the problem. Since you are using MVC3, I am going to assume that you are using Entity Framework?

Ensure that either your DbContext (ef 4.1) or any other Context object is being properly configured to use "TestDB". As for where the SQLExpress db is located, from the original connection string, it appears it is looking at your local SQLExpress server.

I had this same problem when I tried to deploy with appharbor. Look in your project directory - you probably actually have THREE web. Config files - a web.

Config, web.config. Debug and web.config.release. Visual Studio 2010 uses transformations based on your project build state to decide what transformations to apply.

Check out the transformation tester from appharbor to get this figured out. Also be careful because if you have the wrong settings in an Entity Framework project, you may be deleting the database on appharbor every time you make changes to your model. And the account that you have been given the credentials to does not have permission to re-create that database.

If you are using the built-in aspnet user models, make sure you set them up with the appharbor database instead of your local sqlexpress. Here is a How-To on that.

You need to first run the C:\WINDOWS\Microsoft. NET\Framework\\aspnet_regsql. Exe program and point it to your remote (or local) database Here is a link outlining this - msdn.microsoft.com/en-us/library/x28wfk7... then just change the web config entry to point to the new database.

You need to use.

Question 1: Type services. Msc in your Windows->Start->Run box and ensure that the SQL EXPRESS service is started. In your Server Explorer in VS: Connect to Database, choose Sql Server, enter this as your server: .

\SQLEXPRESS You should then be able to test your connection. Question 2: HMMM I can reproduce your same issue by just attempting to change from SQLEXPRESS to my default SQL instance via web. Config .

EF keeps creating the DB in SQLEXPRESS. Interesting but I don't have a clue.

Well that's got me slightly further along, thanks, I can now see sqlexpress.master. Dbo in Server Explorer, but my . Mdf file that I assume I have somewhere isn't there.

SQL EXPRESS is indeed started by the way. – Martin McGirk Jul 10 at 1:40 I tried running aspnet_regsql. Exe (as Doug Stanley suggests) on my sql standard install and pointing to it by removing the \SQLEXPRESS from the connection string in web.

Config BUT it is still using SQLEXPRESS.? – felickz Jul 11 at 12:53.

So I finally worked out what the problem was - aided in no small part by everyone's help here. So thank you. There were two main things I had wrong.

Firstly, turns out that the name of the connection string is important. I needed to name my connection string after the context I'd set up in MVC. So my "TestDB" was wrong, and instead for the video tutorial I linked to in my question the connection string should be called "SportsContext".

So in the end, my connection string entry for Web. Config looked like this: Which interestingly enough is not what they tell you that you should use on appharbor. Secondly, and another key point I was missing, while MVC will happily build your databases for you in SQLEXPRESS, it won't do the same for SQL Server.

And when building them yourself in SQL Server you have to be sure to get everything in correctly, including auto-incrementing ID columns and foreign keys etc. Those two changes were all it took get my site up and working.

Essentially what I'm trying to do is get my head around Microsoft's ASP.NET MVC 3.0. I'm using Visual Studio 2010 Ultimate. I followed the video tutorial at http://www.asp.net/mvc/videos/5-minute-introduction-to-aspnet-mvc which got me up and running and as a result have created a website which accesses a local database.

Does anyone know where that local database is? I believe it's using a default SQLEXPRESS db somewhere. It doesn't show up in Server Explorer, it's not in the App_Data folder.

I cant find it in any folder anywhere.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions