美好的一天,真棒的人!我知道类似的问题已经被问到,但我已经读过其中许多已经没有成功。这里是我的问题:通过Visual Studio 2012连接到SQL Server数据库
我已经在Visual Studio 2012 Express(我正在使用C#)中连接到我在SQL Server Express 2016中创建的数据库中添加了一个数据源。当我运行我的项目并尝试执行任何代码有关的数据库,我得到的错误:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)."
我连接本地,而不是远程。
我已经通过了如下:
- 在创建连接,“测试连接”是成功的。
- 我已经四重检查了我的连接字符串。
- SQL Server正在运行。
- 在SQL Server Management Studio属性中,启用了远程连接(尽管我没有远程连接)。
- 在SQL Server配置管理器的服务下,SQL Server正在运行。在SQL Server网络配置下,共享内存,命名管道和TCP/IP都已启用。
我的连接字符串:
Data Source=name\SQLEXPRESS;Initial Catalog=(catalog name);Integrated Security=True
您可以使用SSMS连接到相同的实例吗?在连接字符串中使用的数据源和相同的用户名和密码? –
嗨。是的,这工作正常。 – Nazgul
@mason谢谢,我编辑它。 – Nazgul