且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

IIS和SQL服务器之间的连接字符串

更新时间:2022-02-18 04:44:01

这的教程如何设置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; }
}