Acrobatics field--View the app connect to the database

Source: Internet
Author: User

When doing a database migration or other maintenance, you need to pause access on the application side, and we can view the IP connected to the data through the view. For ADO, we can also see the name of the app that's connected, but when it comes to Java programs using JDBC, it's hard to know exactly which application is going to access our database, especially when there are many applications running on the application server.

--=============================================

First, for the ADO access, use the following code

SELECT  [net_ip]. session_id,[net_ip]. Connect_time,[net_ip]. Net_transport,[net_ip]. Client_net_address,[net_ip]. Client_tcp_port, se.host_process_id,[net_ip]. Local_net_address,[net_ip]. Local_tcp_port,[hostname]. Hostname,[hostname].[db_name] ,        [hostname]. Net_address,[hostname]. Loginame,[hostname]. Program_name,[net_ip]. Num_reads,[net_ip]. Num_writes,[hostname].text fromSys.dm_exec_connections as [net_ip]        JOIN(SELECT DISTINCThostname, SPID,db_name(sp.dbid) as [db_name], Net_address, Loginame, Program_name, text                fromMaster.. sysprocesses SP CrossAPPLY sys.dm_exec_sql_text (sp.sql_handle)WHEREHostname is  not NULL                         andHostname<> "'             )  asHostname on [net_ip]. session_id= [hostname]. SPID Left JOINsys.dm_exec_sessions SE on [net_ip]. session_id=se.session_id

We can locate the requested server IP according to local_net_address, through host_process_id to view the PID that sends the request, log on to the request server, use Task Manager to find the application of PID.

--=============================================

First of all, for JDBC access, the host_process_id is 0, it is not possible to provide us with valid information, we can use Client_tcp_port to locate the application.

First log on to the requested server, open the cmd window, run the Netstat-ano command to view the server's port usage

In the local address column, look for the value of Client_tcp_port, find the PID for the line, and then find the application based on the PID.

Wow haha, is not very powerful.

Little tricks:

Run netstat-ano>d:\net.txt in cmd, so that the result is saved to d:\net.txt, in the text editor to find the corresponding client_tcp_port, more convenient and quick.

--====================================================

Work overtime in the middle of the night to a hydrology, sister suppression under monsters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.