How to create Linked Server with non-default port - sql

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?

Another way to achieve this (assuming that you have set up 8080 in SQL Server) is with the following code:
EXEC sp_addlinkedserver 'myserver', '', 'SQLNCLI', 'xx.xx.xx.xx,8080'
EXEC sp_addlinkedsrvlogin 'myserver', 'FALSE', NULL, 'user', 'pwd'

In the new linked server dialog, choose "Other data source", select "Microsoft OLE DB Provider for SQL Server" as your provider name, then use this as your provider string:
Data Source=192.168.1.100,1433;Network Library=DBMSSOCN;Initial Catalog=yourdbname;User ID=username;Password=password;
Replace the IP and "1433" with your IP and port number.
More info on connection strings: http://support.microsoft.com/kb/238949

Based on Shane's suggestion, adding an alias worked for me.
(SQL Server 2008 R2):
Open SQL Server Configuration Manager
Expand "SQL Server Configuration Manager (local)"
Expand "SQL Native Client 10.0 Configuration (32bit)"
Click "Aliases"
Right-click in the right-side alias list, and choose "New Alias"
"Alias Name" is whatever you want to reference the linked server as.
"Port No" is your non-default port.
"Protocol" depends, but you can most likely leave this as "TCP/IP".
"Server" is the address of the server you're trying to connect to (not including port).
(repeat the steps for "SQL Native Client 10.0 Configuration" (minus the '32bit' text))
Adding an alias this way allowed me to add a linked server with the Server Type as "SQL Server", without configuring provider options, etc.

Note that 4-part queries will look similar to this:
SELECT * FROM [SQLSERVER,14333].[DATABASE].[dbo].[Table1]

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:
Open SSMS and go to Server Objects > Linked Server > New Linked Server
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.
Select SQL Server for Server Type
Add any credentials required to connect using the Security tab
Query the new server using the format just like SQLDBA specified above.
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'

Related

How to know my server name in SQL Server?

I installed SQL Server but I forgot my server name and now that I install SQL Server Management Studio, it needs the server name.
How can I get server name again?
You can get your server name with Transact-SQL(T-SQL) as shown below:
SELECT ##SERVERNAME -- DESKTOP-OVPADTC\SQLEXPRESS
SELECT SERVERPROPERTY ('ServerName') -- DESKTOP-OVPADTC\SQLEXPRESS
If you installed SQL Server on your local machine, you can get to the installed server using
.
(local)
localhost
YourMachineName
as the server/instance name.
If you installed SQL Server Express with the defaults, you can reach your instance with:
.\SQLEXPRESS
(local)\SQLEXPRESS
localhost\SQLEXPRESS
YourMachineName\SQLEXPRESS
Otherwise, you need to go to Start Menu > SQL Server > Configuration Tools > SQL Server Configuration Manager and see which SQL Server services are running:
If you find a Service Type = SQL Server with a State = Running, the instance name is provided in the brackets behind the "SQL Server" in the Name column - here it is SQL2014. In that case, you can connect to this running SQL Server instance on your local machine using:
.\SQL2014
(local)\SQL2014
localhost\SQL2014
YourMachineName\SQL2014
If the instance name (in brackets) is MSSQLSERVER, this means it's the default, unnamed instance - and you can connect to it with just one of the first four options - just the "local machine server name" - no instance needs to be provided.
When the ssms's launched, the "Connect to Server" appears first,
then in the Server name field it'll have already selected (probably your pc name if you gave default on server installation) the server name.
If it isn't there, then click on it (Server name drop down)
<Browse for more...>
then on the popup "Browse for Servers"
click on "Database Engine"
and you can find your server name there.
There will be only one server name there ,if this is the first server you've created.
Click on the server name and hit OK!

How to connect AWS sql server by sql server express

We have created SQL server database using RDS AWS console. With following configurations:
Availability zone
ap-south-1b
VPC
vpc-07b03fb50131ed688
Subnet group
default-vpc-07b03fb50131ed688
Subnets
subnet-01ea3ba2b300b123d
subnet-019551993b22cc459
Security groups
rds-launch-wizard-1 (sg-08ceba391dda818db)
( active )
Publicly accessible
Yes
But we are not able to connect it with SQL express with local machine. Any help to update security options..
Good day,
Not sure what you mean by connect it with SQL express. My feeling is that you confuse two unrelated application: (1) SQL Server Express and (2) SQL Server Management Studio (SSMS). With that being said, it is possible that you meant to connect from one server to the other using linked server for example. I will answer both options...
Connecting from SSMS to AWS SQL Server
This is well documented in the official AWS system as you can see here. Basically you need to copy your server endpoint from your account.
If this is what you meant so you must understand that SSMS is a client application and had nothing to do with SQL Server (meaning it is not part of SQL Server but totally separate application, which can be install with or without SQL Server like any unrelated app)
Create linked server from local server to AWS SQL Server
If you do mean to connect using linked server from one server to the other, then:
Step 1: Do the same as above option and get the information to connect from SSMS. We need the Server name, user name, and password.
Step 2: Confirm that you can connect from SSMS first.
Step 3: continue to create linked server, and map your remote username to the local server. For this you can use the bellow queries.
USE [master]
GO
-- create linked server to the remote server
EXEC master.dbo.sp_addlinkedserver
#server = N'<Your Server name come here>', -- this is the same information as you use from SSMS
#srvproduct=N'SQL Server';
GO
-- check your list of servers to confirm that you see the new one
select * from sys.servers
GO
-- Now we need to map your remote login to your new linked server
EXEC master.dbo.sp_addlinkedsrvlogin
#rmtsrvname = N'<Your Server name come here>',
#useself = 'FALSE',
#locallogin = NULL ,
#rmtuser = N'RonenAriely', -- enter your remote user name
#rmtpassword = '<Enter Your remote Password here>'
GO
-- that's it, wee can query the remote server from the local server now
--check that your can execute remote query
SELECT name FROM [<Your Server name come here>].master.sys.databases
GO
I hope this solve your issue :-)

Unable to connect to SQL Server 2005

I am trying to connect to SQL Server 2005 express edition from SQL Server Management.
From the server configuration manager, I found the SQL Server Service to be running and within bracket, it's written(SQLEXPRESS). I understand SQLEXPRESS is the instance name, therefore I have to use following string for server name: \SQLEXPRESS.
I am using windows authentication. I am logged into an account that is non admin.
Can someone suggest me how I can establish the connection.
Thanks.
Try .\SQLEXPRESS..
From here:
By default, SQL Server Express
installs as an instance named
"SQLEXPRESS," for example. You connect
to a named instance by specifying the
instance name with the server name in
the connection string. That is why you
normally specify ".\SQLEXPRESS" as the
server name when connecting to a local
SQL Server Express database. The dot
means the local server and \SQLEXPRESS
specifies the SQLEXPRESS named
instance.

Why there is no any Sql Server in Add Connection list

I use Microsoft Visual Studio 2010 Professional (I installed all components).
Here is what I'm trying to do. I create a new ASP.NET project. Then I open Server Explorer (View->Server Explorer), right click on Data Connections and choose Add Connection. Then I choose Microsoft SQL Server and press Continue, but the 'Server name' list is empty.
I launch Sql Server Configuration Manager and it shows that SQL Server is in running state (Agent and Browser are stopped)
Why there is no any Sql Server in Add Connection list?
--------------------------------------------------------------
I allow remote filestream for SQl Server, so no I can choose server in the list, but when I enter new database name and click Ok I get a error "sql server was not found or was not accessible"
--------------------------------------------------------------
Here is a list of installed programs with 'SQL' filter
Have you configured SQL Server to allow remote connections? By default, SQL Server Express Edition and SQL Server Developer Edition do not allow remote connections.
For SQL Server 2005:
How to configure SQL Server 2005 to allow remote connections
For SQL Server 2008:
From start menu of SQL Server 2008, run SQL Server Configuration Manager.
From left side view of SQL Server Configuration Manager, expand SQL Server Network Configuration.
In the right view, you will see the list of SQL Server protocols. By default only Shared Memory is enabled. Enable the other protocols to get your SQL server to accept connections over the network.
Your problem appears to be that you have more than one SQL Server instance installed locally. You will need to use the fully qualified name.

SQL SERVER 2005 Connectivity Problems

I am having a hell of a time trying to connect to the SQL SERVER 2005 database. I am using Windows 7.
Here is the screenshot of the error thrown:
(source: highoncoding.com)
I have been battling this issue for the past week and still no progress.
I have tried the following in the server name:
(local)
localhost
computername
none of them worked!
I just checked in the services section and SQLSERVER EXPRESS is not even there. I am using the following post as a reference:
https://serverfault.com/questions/11745/i-cannot-connect-to-my-local-sql-server-2008
This instance of SQL Server is running on the same PC you're connecting from? That's the implication of 'local'.
Possibilities :
1) Try (local) instead of local for the server name
2) Try 'MSSQLSERVER' as the name
3) Check the SQL Server Configuration Manager shows the same configuration options you're attempting to connect with, eg the same instance name, Named Pipes enabled, services running ok, etc.
EDIT :
Ok, what are you using to connect with? SQL Server Management Studio Express? Are you sure you installed an instance? The lack of SQLExpress in the services list would seem to indicate otherwise.
When you connect to a SQL Server you specify the name in the form {computername}\{instancename}. The {instancename} is the name of the SQL instance which was chosen during the SQL Server installation. For {computername} you can substitute the special names . or local when connecting to the localhost machine. If the SQL Server was installed as the Default instance then the instance name part must be omitted, so the connection Server name becomes just the computer name.
SQL Server Express installs by default an instance named SQLEXPRESS. The corresponding NT service name is MSSQL$SQLEXPRESS. The Server name in the connection dialog is .\SQLEXPRESS, local\SQLEXPRESS, localhost\SQLEXPRESS or {computername}\SQLEXPRESS (they're all the same).
If the SQL Server was installed as the Default instance name then the corresponding NT service name is MSSQLSERVER. The Server name in the connection dialog is ., local, localhost or {computername} (they're all the same).
If the SQL Server was installed as a named instance then the corresponding NT service name is MSSQL${INSTANCENAME}. The Server name in the connection dialog is .\{INSTANCENAME}, local\{INSTANCENAME}, localhost\{INSTANCENAME} or {computername}\{INSTANCENAME} (they're all the same).
When connecting from a remote computer to a SQL Server instance the SQL has to be configured to allow remote connection How to configure SQL Server 2005 to allow remote connections.
Check your SQL server configuration, make sure the TCP connections are enabled. You can also check that the SQL Browser service is started. Make sure you do not have a firewall that gets on the way. Make sure the SQL Server service is also started.
Did you install SQL Server on the default instance, or have you used named instances? If you've used named instances then the server will be server\instancename. If you don't know, then have a look in the Services administrative tool; you'll be able to determine the instance name, if any, from there).
You could also try connecting with the server name as a single period (i.e. simply ".") [caveat... I've not got access to SQL Server at the moment, but I think I've used this before now].