简体   繁体   中英

SQL Connection String failing to connect SQL Instance

I am attempting to debug an application, but when I run it I get the following error message:

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)

I've opened up the 1433 port and double-checked it's open and reachable from my current location. I've also enabled TCP/IP remote connections and can connect remotely using SQL Server Studio Manager.

The connection string I'm using is:

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

I'm 90%sure there's something wrong with the connection string but I'm not sure what?

If you are not sure about the Connection string, use a udl file for testing:

  1. Create a new text file.
  2. Change the extension to .udl (eg 1.txt to 1.udl )
  3. Go to the Connection tab
  4. Insert your credentials ( Servername\\instance , user name + password / Windows security etc)
  5. Check the Allow saving password check box
  6. Click on Test Connection and get a success message.
  7. Click on OK (this will close the form)
  8. Open the 1.udl file in a text editor - It will contain the connection string that was used for the successful connection

Now you can compare the connection strings / use the one you now that works...

Good luck!

在此处输入图片说明

试试这个代码

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM