23224

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?

Answer1:

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

Answer2:

This tutorial how to setup SQL Server 2008 for an ASP.net 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; } }

Answer3:

<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.

Answer4:

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

and it will work ...

Recommend

  • Exception: System.ArgumentException: Keyword not supported: 'initial catalog' when hard co
  • Boostraping symfony 2 for pthread from command
  • What is wrong with this mysql connection string?
  • Process.StartTime Access Denied
  • Giving security priviliege to a scheduler in Java EE 6
  • Can my app be notified when another application starts/stops playing audio?
  • Upgrade project from WorkLight 6.1 to MobileFirst 7.1
  • Command line installation of Code Signing certificates, .p12 files, and mobileprovisions
  • TFS - how do I sum child task hours to parent
  • Deploying a CodeRush plugin from the Community Site
  • How to pass solution folder as parameter in command line arguments (for debug)?
  • Eclipse MTJ doesn't see Java ME SDK 3.0 devices
  • MYSQ & MVC3 SQL connection error \\ ProviderManifestToken but I am using MySQL
  • pyodbc doesn't report sql server error
  • MongoError: Incorrect arguments
  • Django rest serializer Breaks when data exists
  • SignalR .NET Client Invoke throws an exception
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • PHP - How to update data to MySQL when click a radio button
  • Azure Cloud Service Web Role web pages do not load
  • Counter field in MS Access, how to generate?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Proper folder structure for lots of source files
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Getting error when using KSoap library to consume .NET web services
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • embed rChart in Markdown
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How does Linux kernel interrupt the application?
  • Authorize attributes not working in MVC 4
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app