IIS和SQL服务器之间的连接字符串 [英] Connection string between IIS and SQL server

查看:248
本文介绍了IIS和SQL服务器之间的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目的实体框架的Web API Web.config文件中的连接字符串混淆。有很多的变种我试过的,但他们都不是帮助我。目前,连接字符串

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>

我可以访问被称为2012 MyProject的在SQL Server Management Studio中的数据库(甚至远程),使用约翰作为用户名,烤鸭作为密码。

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.

该项目是由IIS服务器在同一台计算机的SQL服务器上运行时,SQL Server的实例名称为 SQLEX $ P $干燥综合征
  我的网页上显示本地主机,但控制器只是回复 500 INTERAL服务器错误每当从SQL数据库的一些数据请求。它看起来像有到数据库的连接。

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.

我有什么补充或者为了得到betweeen IIS和SQL服务器的连接发生变化,或者我怎么能找到问题的原因比较好?

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?

推荐答案

<一个href=\"http://evonet.com.au/setting-up-sql-server-2008-for-an-asp-net-website-on-iis-7-0/#!$p$pttyPhoto\"相对=nofollow>这的教程如何设置SQL Server 2008中的IIS 7.0上ASP.net网站给我带来接近的解决方案。

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


  1. 安装SQL Server。

  2. 允许TCP / IP连接到SQL服务器。

  3. 附加数据库。

  4. 创建一个登录。我使用的是SQL身份验证。

  5. 分配用户权限的数据库。

  6. 配置您的数据库连接字符串。

更改我的连接字符串的名称帮我终于建立连接。

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; }
}

这篇关于IIS和SQL服务器之间的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆