无法为C#应用程序的远程桌面创建连接字符串 [英] Unable to create connectionstring for a remote desktop for a C# application

查看:80
本文介绍了无法为C#应用程序的远程桌面创建连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Windows服务,它将数据从一个数据库复制到另一个数据库。源数据库位于远程位置,下面是使用 SqlConnectionStringBuilder 并创建连接字符串的函数:

I want to create a Windows service which will copy data from one database to another database. The source database is in a remote location, below is the function using SqlConnectionStringBuilder and creating the connection string:

public string CreateConnectionString()
{
    SqlConnectionStringBuilder b = new SqlConnectionStringBuilder();
    b.DataSource = "ABCKOL-BCKOFF\\SQLEXPRESS";
    b.InitialCatalog = "netXs";
    b.IntegratedSecurity = false;
    b.UserID = "userid";
    b.Password = "password";

    return string connectionString = b.ConnectionString;
}

但不幸的是,它显示出这样的错误:

But unfortunately, it is showing an error like this:

有什么我应该知道的更多/检查更多的东西吗?

Is there anything I should know more/check more?

推荐答案

尝试从命令提示符下执行 telnet localhost 1433 服务正在运行),如果接受连接没有任何错误,那么您的SQL Server真的准备好接受连接。否则,请按照以下步骤解决问题:

Try to do telnet localhost 1433 from command prompt (from the same server where SQL services running), if the connection accepted without any error, then your SQL server really ready to accept connections. Otherwise follow these steps to troubleshoot the issue:


  • 确保已启用 TCP / IP 协议

  • 验证是否为SQL Express服务配置了自定义端口(通过SQL Server配置管理器)(根据屏幕截图)

如果未配置自定义端口


  1. 确保 SQL Browser服务正在运行

  2. 在Windows防火墙中创建规则以接受TCP上的传入连接端口 1433 1434(TCP和UDP)

  3. 重新启动SQL Browser服务

  4. 再次执行 telnet localhost 1433 进行验证

  1. Make sure SQL Browser service is running
  2. Create a rule in Windows Firewall to accept incoming connections on TCP ports 1433 and 1434 (TCP and UDP)
  3. Restart SQL Browser service
  4. Do telnet localhost 1433 again to verify

如果已配置自定义端口


  1. 在Windo中创建规则ws防火墙接受自定义TCP端口上的传入连接

  2. 重新启动SQL服务

  3. 执行 telnet localhost< custom port> 进行验证

  4. 将连接字符串更改为 DataSource = ABCKOL-BCKOFF,<自定义端口>

  1. Create a rule in Windows Firewall to accept incoming connections on Custom TCP ports
  2. Restart SQL service
  3. Do telnet localhost <custom port> to verify
  4. Change the connection string to DataSource = "ABCKOL-BCKOFF,<custom port>"

这篇关于无法为C#应用程序的远程桌面创建连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆