SQL 服务器 Express 连接字符串错误

SQL Server Express connection string error

正在尝试找出 SQL Server Express 数据库的正确连接字符串。尝试将我的应用程序发布到 IIS 并在发布到我的托管站点之前进行测试。

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: 26 - Error Locating Server/Instance Specified)

我开始了here and also used connectionstrings.com. I also started reading the deploy asp.net app using SQL Server Compact article here

使用这个连接字符串

Data Source=.\SQLExpress;AttachDbFilename=H:\DB\Guestbook.sdf;Integrated Security=True

我得到上面的错误

这个连接字符串

<add name="DefaultConnection" 
     connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI; database=Guestbook; AttachDBFilename=|DataDirectory|Guestbook.sdf" 
     providerName="System.Data.SqlClient" />` 

引发信任级别错误。我已更改为 medium 和 full,但仍然出现两个错误之一。

我尝试了几个不同字符串的变体,但没有成功。

谢谢

请确认 SQL 服务已在 services.msc 中启动并使用主机名 ej 的完整实例:HOSTNAME\SQLEXPRESS

文件扩展名表明这不是 SQL Server Express 数据库,因此您必须使用:

Data Source=<Full path to file>

Data Source=|DataDirectory|Guestbook.sdf