SQL 连接字符串无法连接 SQL 实例

SQL Connection String failing to connect SQL Instance

我正在尝试调试应用程序,但是当我 运行 它时,我收到以下错误消息:

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)

我已经打开了 1433 端口并仔细检查它是否打开并且可以从我当前的位置访问。我还启用了 TCP/IP 远程连接,并且可以使用 SQL Server Studio Manager 进行远程连接。

我使用的连接字符串是:

Data Source=xx.xx.xxx.xx, 1433;Network Library=DBMSSOCN;Initial Catalog=KnightOwl-Demo;Persist Security Info=True;User ID=KnightOwlGentleshaw; Password=xxxxxx

我 90% 确定连接字符串有问题,但我不确定是什么?

试试这个代码

Data Source=xx.xx.xxx.xx;Initial Catalog=KnightOwl-Demo;Persist Security Info=True;

如果您不确定连接字符串,请使用 udl 文件进行测试:

  1. 创建一个新的文本文件。
  2. 将扩展名更改为 .udl(例如 1.txt 更改为 1.udl
  3. 转到 Connection 选项卡
  4. 输入您的凭据(Servername\instance、用户名 + 密码/Windows 安全等)
  5. 选中 Allow saving password 复选框
  6. 单击 Test Connection 并收到成功消息。
  7. 单击“确定”(这将关闭表单)
  8. 在文本编辑器中打开 1.udl 文件 - 它将包含用于成功连接的连接字符串

现在您可以比较连接字符串/使用您现在可以使用的连接字符串...

祝你好运!