Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

sql server - Unable to create connectionstring for a remote desktop for a C# application

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:

Error Message

Is there anything I should know more/check more?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  • Make sure TCP/IP protocol enabled
  • Verify if the custom port configured (via SQL Server Configuration manager) for SQL Express service (as per screenshot)

enter image description here

If the custom port NOT configured

  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

If the custom port configured

  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>"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...