Connection string between IIS and SQL server

I'm confused by the connection string in the Web.config file of project with Entity Framework Web API. There are a lot of variants I tried, but none of them was helping me out. Currently the connection string is

<connectionStrings> <add name="DefaultConnection" connectionString="Server=.\SQLEXPRESS;Database=MyProject;User Id=John;Password=duck;" providerName="System.Data.SqlClient" /> </connectionStrings>

I can access the database which is called MyProject in SQL Server Management Studio 2012 (even from remote), using John as username and duck as password.

The project is run by an IIS server on the same machine as the SQL server, the SQL server's instance name is SQLEXPRESS. My webpage is displayed on localhost, but the controller just replies 500 Interal server error whenever some data from the sql database is requested. It looks like there is no connection to the database.

What do I have to add or change in order to get a connection betweeen IIS and SQL server, or how can I locate better the problem's cause?


Use the Event Viewer to get more information on what the 500 error actually is.


This tutorial how to setup SQL Server 2008 for an website on IIS 7.0 brought me close to the solution.

Basically, what you need to do is

<ol> <li>Install SQL server.</li> <li>Allow TCP/IP connections to the SQL server.</li> <li>Attach your database.</li> <li>Create a login. I'm using SQL Authentication.</li> <li>Assign the user permissions to your database.</li> <li>Configure your database connection string.</li> </ol>

Changing the name of my connection string helped me establish the connection finally.

<connectionStrings> <add name="MyProjectContext" connectionString="Server=.\SQLEXPRESS;Database=MyProject;User Id=John;Password=duck;" providerName="System.Data.SqlClient" /> </connectionStrings>

The context model required this name.

public class MyProjectContext : DbContext { public MyProjectContext() : base("name=MyProjectContext") { } public DbSet<Model1> Model1 { get; set; } public DbSet<Model2> Model2 { get; set; } }


<connectionStrings> <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MyProject;User ID=John;Password=duck" providerName="System.Data.SqlClient" /> </connectionStrings>

Please try the above connection syntax.


Basically just amend your connection string using Integrated Security=False like :

and it will work ...

人吐槽 人点赞



用户名: 密码:
验证码: 匿名发表


查看评论:Connection string between IIS and SQL server