在本地主机上使用 SQL Server Express 进行 Web 应用程序

Using SQL Server Express on localhost for a web application

我创建了一个 Web 应用程序,它应该 运行 在本地,我不需要将它传输到主机,但是当我尝试 运行 我在本地的 Web 应用程序时,我得到了这个错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.

使用 SQL Server 2008 R2 运行 的其他项目没有任何问题,但使用 SQL Server Express 的这个项目显示此错误。

转到

Start Menu >
    Microsoft SQL Server 2008 R2 > 
        Configuration Tools > 
            SQL Server Configuration Manager

您应该会看到如下所示的屏幕:

如果您有两个实例 运行,右侧应该有 两个条目 "SQL Server (....)" 和 State = running。括号中的值是每个的 实例名称 - 是什么?

  • MSSQLSERVER 代表 默认、未命名的 实例 - 您可以使用 .(local) 或单独的机器名称

  • SQLEXPRESS 是 SQL Server Express 安装的默认设置,您使用 .\SQLEXPRESS 连接到它, (local)\SQLEXPRESSyour-machine-name\SQLEXPRESS

  • 如果实例名称是其他名称 - 那是您需要在冒号 (.) 或 (local) 之后使用的实例名称以在本地连接到它