0

Need Help with straightforward MVC deploy ...

I cannot get a DB connection to a MVC web app other than by using LocalHost on an Azure VM.

The problem occurs with for a webapp I'm developing and for the out-of-the-box VS2013 MVC template ... when deployed to a Bizspark preconfigured VM.

When browsing with VS on local host and can update records, but cannot for the IIS hosted site.

Workflow

Pre-deploy: enabled EF migrations

Deploy: Web Publisher

ConnectionStrings:

 <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|aspnet-WebApplication1-20150429124346.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient"/>
    <add name="DefaultConnection_DatabasePublish" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|aspnet-WebApplication1-20150429124346.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient"/>

Question

Are there configuration requirements for SQL to get this to work?

I'll piece together what Explicat recommends, but it seems there should be a straightforward solution with documentation to using integrated security.

2
  • I've read your question 3 times and I don't understand what you're claiming or asking. Are you saying that your app isn't able to connect to the database when hosted on an Azure VM? In that case, we need to know a lot more information, like ... where is your production database? Is it on the same Azure VM as your IIS-hosted website? Are you using SQL Server Express? What connection string are you using to connect? Both your connection strings shown above are using LocalDb which is NOT the same as localhost. LocalDb refers to a single-connection local file, as opposed to a DB server. Commented Apr 29, 2015 at 15:50
  • Yes, app doesn't connect to db when hosed on an Azure VM. SQL server and IIS are running on same 2012 server. SQL is enterprise 2012. Microsoft provisions these pre-configured machines for Bizspark Members, so not entirely my configuration. Localhost / IIS express is run from same server as VS comes installed on it. The connection strings above work for with IIS express... and are what are recommended by Web Publish, so I used as a starting point. Commented Apr 29, 2015 at 16:17

1 Answer 1

0

Okay, so if you're using SQL Server Enterprise Edition on your VM, then your connection string ought to look something like this:

Data Source=SERVERNAME;Initial Catalog=DATABASENAME;User ID=SQLUSERNAME;Password=SQLUSERPASSWORD

You will likely want to use an explicit SQL login and password rather than Integrated Security. With Integrated Security, you are trying to connect to the database using the same credentials as the calling process. But with IIS, the calling process is the process under with the Application Pool is running under, which is usually configured as some built-in account that doesn't normally have access to your database. So use an explicit SQL login/password.

Connect with SQL Management Studio using that same login/password to ensure that the connection works correctly, before trying it in your website. If it doesn't work, please post the details of the error or symptom you're seeing.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I changed deployment from AzureVM to Azure Web Apps. Out of curiosity and because I may come back to VM hosting are you aware of any other SQL server requirements like TCP/IP access ?
Yes, if your SQL Server is on a separate machine than your website, then it will need to enable TCP/IP access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.