Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Linked Server with non-default port

I want to create a Linked Server in MS SQL Server 2000 to a MS SQL 2005 Server which runs on port x (not the default port 1433). But it doesn't work, as I can't specify the port anywhere!?

Using sqlcmd (specifying port x), I can connect to the server without problems - but I can't set it up as a Linked Server.

How can this be done?

like image 562
räph Avatar asked Sep 18 '09 15:09

räph


People also ask

What port do linked servers use?

By default linked servers also use port 1433. For better answers on performance questions, click on the following...

How will you create a linked server in SQL Server to access?

Follow the steps below to create a linked server from the Object Explorer. Open SQL Server Management Studio and connect to an instance of SQL Server. In the Object Explorer, expand the node for the SQL Server database. In the Server Objects node, right-click Linked Servers and click New Linked Server.


2 Answers

Note that 4-part queries will look similar to this:

  SELECT * FROM [SQLSERVER,14333].[DATABASE].[dbo].[Table1]
like image 110
smoore4 Avatar answered Sep 22 '22 14:09

smoore4


I had to do this today as well (add a linked server with non-default port). In my case it was adding a SQL Server 2014 linked server to a SQL Server 2016.

Steps using SQL Server Management Studio:

  1. Open SSMS and go to Server Objects > Linked Server > New Linked Server
  2. Use this format for the Linked Server ip-address-of-linked-server\instance-name,non-default-port or, 192.168.10.5\dev-sql,25250. Instance name is required only if that instance is not the default instance on target linked server. Also, you can replace ip address by host name if the linked server is on your local network.

  3. Select SQL Server for Server Type

  4. Add any credentials required to connect using the Security tab
  5. Query the new server using the format just like SQLDBA specified above.

example screenshot

Same thing using T-SQL:

EXEC master.dbo.sp_addlinkedserver @server = N'192.168.10.5\dev-sql,25250', @srvproduct=N'SQL Server'

EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'192.168.10.5\dev-sql,25250',@useself=N'False',@locallogin=NULL,@rmtuser=N'my_username',@rmtpassword='my_pswd'

like image 32
joym8 Avatar answered Sep 21 '22 14:09

joym8