Identifying the IP,PORT and Instance of a SQL Server Instance - sql-server

I am trying to connect to SQL server instance in a remote system(a VPN has been set up between my machine and the server). The IP address I am supposed to connect to is 192.168.1.X, which I can ping from my machine.
When I RDP into the server hosting the SQL server and run in Sql server studio:
USE master GO xp_readerrorlog 0, 1, N'Server is listening on', 'any', NULL, NULL, N'asc' GO
I get the following:
LogDate ProcessInfo Text
2016-03-05 12:21:37.630 Server Server is listening on [ 'any' 12345],
2016-03-05 12:21:37.630 Server Server is listening on [ 'any' 12345].
Question 1: Does this mean that the server is listening to any queries in ipv6 and ipv4 IP for the port 12345?
Question 2: When I check the SQL TCP/IP setting in the host server, I see that the ipv6 IP is 127.0.0.Y. Should it not be 192.168.1.X? How do I find out what it the IP I am supposed to connect to?
TCP Dynamic ports

RDP into the server, and then run the SQL Configuration Manager. Open up SQL Native Client 11.0 Configuration (or whatever version it is if not 11) and select Client Protocols under it. In the right-hand pan el, select TCP/IP, right-click it and select Properties.
You can see that it shows the port it's ljstening on (1433 here, which is the default). If the port is not 1433 you can sepcify it in the connection string as Data Source=servername,portnumber e.g.Data Source=MyServerName,12345 (if 12345 is the port).
BTW, check that TCP/IP is enabled: if it's not then the port doesn't really matter!

Related

How to connect SQL Server by host IP Address

I'm trying to connect new host in SQL Server using IP address, but I got some trouble when I'm trying to log in SSMS 2017. I'm still relatively newbie about using SQL Server. Here's the error message:
when I'm trying to login:
And here when I check SQLCMD
I've been trying:
1. Restart Service SQL Server
2. Enable all Protocols for MSSQLSERVER (include TCP/IP and Named Pipes)
3. Allow remote connections
4. Enable SQL Server Browser
Check your SQL Server log to ensure that it's listening on the IP address(es) you expect. You should see an entry during startup like:
Server is listening on [ 'any' <ipv4> 1433].

SQL network-instance related issue (with error 258)

I get the following message when trying to connect to SQL database from a remote machine using MS Management Studio with Server Name [ XX.XXX.XXX.XXX,1433\MyServerName ] and SQL authentication:
Cannot connect to XX.XXX.XXX.XXX,1433\MyServerName.
ADDITIONAL INFORMATION:
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: TCP Provider, error: 0 - The wait operation timed out.) (Microsoft SQL Server, Error: 258)
The wait operation timed out
I have done the following:
Allowed remote connection in Server Properties window in SQL Management Studio
Configured server machine to have static IPv4/DNS addresses.
Enabled TCP/IP in SQL Configuration Manager (in SQL Server Network Configuration)
In TCP/IP properties, adjusted [ Protocol -> Listen All -> No ] & set IP[1-8] to TCP port 1433 and IPAll port to 1433 (TCP dynamic ports left blank)
Set Inbound/Outbound enable connection (Domain, public, private) rules in Windows Firewall for ports TCP 1433, UDP 1434 (should make no difference, since port is specified), service executables: sqlbrowser.exe in C:\Program Files (x86)\Microsoft SQL Server\90\Shared (not used I think because port is specified) and sqlservr.exe in C:\Program Files\Microsoft SQL Server\MSSQL13.MyServerName \MSSQL\Binn
Set NAT actions in server-side router for ports 1433 (TCP), 1434 (UDP) (again, should not matter) to server's local IPv4 address and ports 1433, 1434 accordingly.
Made sure SQL service is running, ports are open and listening on server machine.
I can connect to the database on server machine using Windows or Sql credentials with either PC name, or machine's local IPv4.
Interesting thing is, when >telnet XX.XXX.XXX.XXX 1433 is run, it takes about 10-12 seconds to fail (Could not open connection to the host, on port 1433: Connect failed), but I can see the 2 packets coming to the router itself. Same with the login using SQL Manager - packets come to the router, but either server machine refuses (doesn't resolve?) the connection, or it doesn't even get to the machine.
Appreciate your suggestions.
Versions used:
MS SQL Server 2016 Express, MS SQL Management Studio 17, SQL Server 2016 Configuration Manager, Windows 10 Pro.
Have you tried telnet on 1433 locally?
Are you sure your local connection is using TCP/IP? By default, local connections use DBNMPNTW (named pipes) which uses shared memory on the back end for local connections and is faster than TCP/IP.
When SQL Server is working correctly on TCP/IP telnet will connect and leave you blinking waiting for protocol-- it doesn't hang for 10-12 seconds and fail.
If telnet works locally but not remotely, then you know the problem is in the networking layer (firewall, NAT, routing, etc.). If it does not, then the problem is in the SQL configuration setup. Did you restart the service after changing the connection settings?

Can't connect to SQL Server on Server 2008 R2 VM; port 1433 is open

I have a virtual machine running Windows Server 2008 R2 and SQL Server 2008 R2. The host is running Windows 7. I can connect to the SQL server from the VM using SQL Server authentication, but I can't connect from the host using the same method and credentials. I can ping the VM from the host, but I can't telnet to port 1433. On the VM, port 1433 is open through the firewall, TCP/IP is enabled on the SQL instance, and all IP addresses in TCP/IP properties are enabled. I have verified that SQL Server is listening on port 1433. I've been trying to figure this out for two days and I'm about at wit's end. Any ideas?
The problem turned out to be the IP address I was trying to connect on. The VM would respond to pings, but nothing else was listening there, I take it. Changing the IP address for the VM in my hosts file to the first one listed under the VM's ipconfig fixed it. (I'd taken the IP address I was trying to use from SQL Server Configuration Manager, which got it from ???.) Our network guy figured it out for me, so I can't give more details, sorry.
Try this:
Goto SQL Server Configuration Manager from start menu then from the left pane choose SQL Server Network Configuration then choose your instance name..
Then from the right pane choose TCP/IP .. make sure it's enabled then :
In its properties > IP Addresses clear any field named TCP Dynamic Ports and for any field named TCP Port set its value to 1433

Firewall Port 1433 not opening

I am using MS Server 2008 with MSSQL 2008-R2 as database server.
Each time for some work i have to login to server via Remote connection.I tried to configure
the SQL Server remote connection on, followed the following steps....
1.Created Inbound and outbound rules for tcp port 1433.
2.In sqlserver configuration manager ,all is set for IP address and POrt no properties.
3.Set the SqlServer instance for remote connections.
But still its not working.
Also when i checked port 1433 for tcp on local computer it is shown closed.
thanks in advance.......
Probably port 1433 is disabled, so enable it using MS WIndows firewall.
or just use
netsh firewall set portopening protocol = TCP port = 1433 name = SQLPort mode = ENABLE scope = SUBNET profile = CURRENT
Probably MS SQL Server Browser Service is not running. So go to Services and start it.
or just execute under Run menu
%windir%\system32\services.msc
Probably TCP/IP channel is disabled under SQL Server 2008/2014 Configuration Manager. SO go there and enable all TCP/IP options.
Just in case at the same place (SQL Server 2008/2014 Configuration Manager) make sure you have 1433 port.
Make sure that SQL server is configured to allow remote connections. Use MS SQL Management Studio and right click on the top node which server itself.
In the SQL Server Configuration Manager->SQL Server Network Configuration->Protocols, check that named pipes and tcp/ip are enabled.
If that doesn't work then it may be your firewall blocking it, try this link: http://msdn.microsoft.com/en-us/library/cc646023.aspx
This may be useful too:
http://support.microsoft.com/kb/287932
If named pipes and TCP/IP access are already enabled in SQL Server Configuration Manager, then you need to either add a rule for UDP port 1434, or a rule for sqlbrowser.exe so that the SSMS client can talk to the SQL Server Browser service.
I actually see people having this problem surprisingly often so I wrote up an explanation here: http://blog.dereenigne.com/microsoft-sql-server-dynamic-ports-windows-firewall-and-you/
If you're trying to connect to an SQL Server Express instance as is my case right now... it doesn't use port 1433 by default. One must check the IpAll => TCP Dynamic Ports in Sql Server Configuration Manager. Mine is 52848.
After entering the correct port 52848 in DbSchema app (the one I'm trying to use), it connected successfully.
Check the following screenshot:
This is the way to go:
The default SQL Server express installation does not enable TCP
network protocols, so here are some steps to take to be able to
communicate with SQL Server Express. These steps should be similar for
MS SQL Server Express 2017, 2016, 2014, 2012, 2008, and 2005.
Launch the SQL Server Configuration Manager. It should be in the Start -> Programs -> Microsoft SQL Server 2005 -> Configuration Tools start menu option.
Select the SQL Server 2005 Network Configuration tab. There should be a Protocols for SQLExpress option, and one of the protocols should be TCP IP.
Enable the TCP IP protocol if it is not enabled.
The default port for SQL Express may not be 1433. To find the port it is listening on, right-click on the TCP IP protocol and scroll all the way down to the IP All heading. There should be a section called TCP Dynamic Ports. This should list the port SQL Express is listening on. You can then put this value into the port field when adding the connection profile via RazorSQL.
Make sure to restart SQL Express before trying to connect.
Text kindly reproduced from:
https://razorsql.com/docs/support_sqlserver_express.html
I had multiple NICs in my server. When I went to SQL Server Network Configuration -> TCP/IP and right clicked for properties there was a list of the NICs and at the bottom was the open port for my SQLEXPRESS. It was not 1433..... I do not know if there is a default but mine was in the 49,000 s.

How to find the port for MS SQL Server 2008?

I am running MS SQL Server 2008 on my local machine. I know that the default port is 1433 but some how it is not listening at this port. The SQL is an Express edition.
I have already tried the log, SQL Server Management Studio, registry, and extended stored procedure for finding the port. But, I could not find it. Please help me. Thanks.
Click on Start button in Windows.
Go to All Programs -> Microsoft SQL Server 2008 -> Configuration Tools -> SQL Server Configuration Manager
Click on SQL Native Client 10.0 Configuration -> Client Protocols -> TCP/IP
double click ( Right click select Properties ) on TCP/IP.
You will find Default Port 1433.
Depending on connection, the port number may vary.
You could also look with a
netstat -abn
It gives the ports with the corresponding application that keeps them open.
Edit: or TCPView.
Here are 5 methodes i found:
Method 1: SQL Server Configuration Manager
Method 2: Windows Event Viewer
Method 3: SQL Server Error Logs
Method 4: sys.dm_exec_connections DMV
Method 5: Reading registry using xp_instance_regread
Method 4: sys.dm_exec_connections DMV
I think this is almost the easiest way...
DMVs return server state that can be used to monitor SQL Server Instance. We can use sys.dm_exec_connections DMV to identify the port number SQL Server Instance is listening on using below T-SQL code:
SELECT local_tcp_port
FROM sys.dm_exec_connections
WHERE session_id = ##SPID
GO
Result Set:
local_tcp_port
61499
(1 row(s) affected)
Method 1: SQL Server Configuration Manager
Step 1. Click Start > All Programs > Microsoft SQL Server 2012 > Configuration Tools > SQL Server Configuration Manager
Step 2. Go to SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for
Step 3. Right Click on TCP/IP and select Properties
Step 4. In TCP/IP Properties dialog box, go to IP Addresses tab and scroll down to IPAll group.
If SQL Server if configured to run on a static port it will be available in TCP Port textbox, and if it is configured on dynamic port then current port will be available in TCP Dynamic Ports textbox. Here my instance is listening on port number 61499.
The other methods you can find here: http://sqlandme.com/2013/05/01/sql-server-finding-tcp-port-number-sql-instance-is-listening-on/
I came across this because I just had problems creating a remote connection and couldn't understand why setting up 1433 port in firewall is not doing the job. I finally have the full picture now, so I thought I should share.
First of all is a must to enable "TCP/IP" using the SQL Server Configuration Manager under Protocols for SQLEXPRESS!
When a named instance is used ("SQLExpress" in this case), this will listen on a dynamic port. To find this dynamic port you have couple of options; to name a few:
checking ERRORLOG of SQL Server located in '{MS SQL Server Path}\{MS SQL Server instance name}\MSSQL\Log' (inside you'll find a line similar to this: "2013-07-25 10:30:36.83 Server Server is listening on [ 'any' <ipv4> 51118]" --> so 51118 is the dynamic port in this case.
checking registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\{MSSQL instance name}\MSSQLServer\SuperSocketNetLib\Tcp\IPAll, for my case TcpDynamicPorts=51118.
Edit: {MSSQL instance name} is something like: MSSQL10_50.SQLEXPRESS, not only SQLEXPRESS
Of course, allowing this TCP port in firewall and creating a remote connection by passing in: "x.x.x.x,51118" (where x.x.x.x is the server ip) already solves it at this point.
But then I wanted to connect remotely by passing in the instance name (e.g: x.x.x.x\SQLExpress). This is when SQL Browser service comes into play. This is the unit which resolves the instance name into the 51118 port. SQL Browser service listens on UDP port 1434 (standard & static), so I had to allow this also in server's firewall.
To extend a bit the actual answer: if someone else doesn't like dynamic ports and wants a static port for his SQL Server instance, should try this link.
In the ERROLOG log for a line like below. If you don't see it the SQL Server isn't enabled for remote access, or it is just not via TCP. You can change this via the SQL Server Configuration Manager.
Server is listening on [ 192.128.3.2 <ipv4> 1433].
Try this (requires access to sys.dm_exec_connections):
SELECT DISTINCT
local_tcp_port
FROM sys.dm_exec_connections
WHERE local_tcp_port IS NOT NULL
I solved the problem by enabling the TCP/IP using the SQL Server Configuration Manager under Protocols for SQLEXPRESS2008, i restarted the service and now the "Server is listening on" shows up in the ERRORLOG file
I use the following script in SSMS
SELECT
s.host_name
,c.local_net_address
,c.local_tcp_port
,s.login_name
,s.program_name
,c.session_id
,c.connect_time
,c.net_transport
,c.protocol_type
,c.encrypt_option
,c.client_net_address
,c.client_tcp_port
,s.client_interface_name
,s.host_process_id
,c.num_reads as num_reads_connection
,c.num_writes as num_writes_connection
,s.cpu_time
,s.reads as num_reads_sessions
,s.logical_reads as num_logical_reads_sessions
,s.writes as num_writes_sessions
,c.most_recent_sql_handle
FROM sys.dm_exec_connections AS c
INNER JOIN sys.dm_exec_sessions AS s
ON c.session_id = s.session_id
--filter port number
--WHERE c.local_tcp_port <> 1433
USE master
GO
xp_readerrorlog 0, 1, N'Server is listening on', 'any', NULL, NULL, N'asc'
GO
[Identify Port used by Named Instance of SQL Server Database Engine by Reading SQL Server Error Logs]
You can use this two commands: tasklist and netstat -oan
Tasklist.exe is like taskmgr.exe but in text mode.
With tasklist.exe or taskmgr.exe you can obtain a PID of sqlservr.exe
With netstat -oan, it shows a connection PID, and you can filter it.
Example:
C:\>tasklist | find /i "sqlservr.exe"
sqlservr.exe 1184 Services 0 3.181.800 KB
C:\>netstat -oan | find /i "1184"
TCP 0.0.0.0:1280 0.0.0.0:0 LISTENING 1184
In this example, the SQLServer port is 1280
Extracted from: http://www.sysadmit.com/2016/03/mssql-ver-puerto-de-una-instancia.html
This may also be done via a port scan, which is the only possible method if you don't have admin access to a remote server.
Using Nmap (http://nmap.org/zenmap/) to do an "Intense TCP scan" will give you results like this for all instances on the server:
[10.0.0.1\DATABASE]
Instance name: DATABASE
Version: Microsoft SQL Server 2008 R2 RTM
Product: Microsoft SQL Server 2008 R2
Service pack level: RTM
TCP port: 49843
Named pipe: \\10.0.0.1\pipe\MSSQL$DATABASE\sql\query
Important note: To test with query analyzer or MS SQL Server Management Studio you must form your server name and port differently than you would normally connect to a port, over HTTP for instance, using a comma instead of a colon.
Management Studio Server Name: 10.0.0.1,49843
Connection String: Data Source=10.0.0.1,49843
however
JDBC Connection String: jdbc:microsoft:sqlserver://10.0.0.1:49843;DatabaseName=DATABASE
This works for SQL Server 2005 - 2012. Look for event id = 26022 in the error log under applications. That will show the port number of sql server as well as what ip addresses are allowed to access.
In addition to what is listed above, I had to enable both TCP and UDP ports for SQLExpress to connect remotely. Because I have three different instances on my development machine, I enable 1430-1435 for both TCP and UDP.

Resources