我在连接我的应用程序到数据库时非常困难。我尝试使用连接字符串中的(localdb)\MSSQLLocalDB连接到数据库,但是我遇到了这个错误:
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.
)
我可以使用 (localdb)\MSSQLLocalDB 从 SSMS 连接到 SQL Server。
为了测试,我将数据源更改为我的实例的命名管道,并且可以从 (我的应用程序) web config 和 SSMS 连接到数据库。唯一的问题是,实例在不活动后会停止,当我手动重新启动实例时,命名管道会更改。
有人能帮助我解决无法使用 localdb 连接的问题吗?
我正在使用的连接字符串:
工作中:
<add name="constr" connectionString="Data Source=np:\\.\pipe\LOCALDB#FF072C16\tsql\query;Initial Catalog=hands; Integrated Security=True" providerName="System.Data.SqlClient" />
不起作用:
<add name="constr" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=hands; Integrated Security=True" providerName="System.Data.SqlClient" />