2017-04-07 103 views
1

美好的一天,真棒的人!我知道类似的问题已经被问到,但我已经读过其中许多已经没有成功。这里是我的问题:通过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 
+0

您可以使用SSMS连接到相同的实例吗?在连接字符串中使用的数据源和相同的用户名和密码? –

+0

嗨。是的,这工作正常。 – Nazgul

+0

@mason谢谢,我编辑它。 – Nazgul

回答

0

您可能需要在防火墙上打开的SQL端口1433

+0

我已经禁用了我的防火墙;效果不同? – Nazgul

+0

禁用防火墙应该这样做。您可以尝试将端口号放入查询字符串中。 –

0

您可能需要启用服务器属性SQL Server和Windows身份验证模式 >安全性>服务器身份验证(通过SQL Server Management Studio)

+0

它已启用。 – Nazgul

+0

远程连接怎么样? – PacoDePaco

+0

@PawelKucharski我没有远程连接。尽管如此,我曾试图使它无济于事。 – Nazgul

相关问题