From: http://blog.csdn.net/linghe301/article/details/38925481
A lot of users have recently consulted in ArcGIS engine that want to be able to disconnect other clients to connect to ARCSDE users, in fact, I think that ArcGIS engine is a business function, disconnecting other client user connection is a managed function, these operations should not be in a piece, However, the needs of users may be a certain rationality. In particular, ArcGIS10.1 also does integrate the functionality of ARCSDE management into ArcGIS for Desktop, indicating that this feature implementation may be feasible.
Prior to ArcGIS 10.1, this feature cannot be implemented using ArcGIS engine because ArcGIS engine does not provide the relevant interface at all.
ArcGIS10.1 includes a later version that can be implemented using ArcGIS engine, which synchronizes the functionality of ArcGIS 10.1 for desktop synchronization.
Test environment:
User 1:aaa, including the roles of Connect and resouces
User 2:bbb, including DBA authority
User 3:sde, including SDE permissions
These three users are a single instance, sometimes referred to as the SDE user.
If an ARCSDE command is used, the user should be able to understand that the Sdemon-o kill command was provided to disconnect the associated SDE user, primarily by obtaining the SessionID of the connecting user, and then invoking the command kill.
- C:\users\li>sdemon-o Kill
- ESRI ArcSDE System Monitor Utility Fri 29 14:50:02 2014
- -------------------------------------------------------------------------
- Sdemon-o kill-t {all | <pid>} [-U <db_user_name>] [-P <db_admin_password
- ;]
- {[-I <service>] [-S <server_name>] | [-H <sde_directory>]}
- [-D <database>] [-N]
- Sdemon-h
- Sdemon-?
Then ArcGIS engine also uses this command, which is integrated in the IDatabaseConnectionInfo4 Disconnectuser, passing in the SessionID of the relevant parameters.
------------------------------------------------------------------
Copyright, the article allows reprint, but must be linked to the source address, otherwise investigate legal responsibility!
Recommended to see reproduced, please direct access to the genuine link to get the latest ArcGIS technical articles
blog:http://blog.csdn.net/linghe301
------------------------------------------------------------------
The specific code is as follows:
The code does not consider the logical judgment of lock.
- Public static void Test ()
- {
- Try
- {
- Iworkspace PWS = getsdeworkspace ("localhost", "LOCALHOST/ORCL", "SDE", "SDE", "SDE") . DEFAULT ");
- IDatabaseConnectionInfo4 pdcinfo = PWS as IDatabaseConnectionInfo4;
- Ienumuserinfo penumusers = pdcinfo.connectedusers;
- Iuserinfo puser = Penumusers.next ();
- int Psessionid; //Get SessionID of connected users
- string susername = ""; Connect user name
- string sclientname = ""; Connect user's machine name
- string sconnetiontime = ""; Connect user's Start connection time
- While (puser! = null)
- {
- if (!puser.isownconnection)
- {
- Psessionid = Puser.sessionid;
- sUserName = Puser.name;
- Sclientname = Puser.clientname;
- Sconnetiontime = PUser.ConnectionTime.ToString ();
- //Disconnect users via user's SessionID
- Pdcinfo.disconnectuser (Psessionid);
- }
- Puser = Penumusers.next ();
- }
- }
- catch (Exception e)
- { }
- }
- public static Iworkspace getsdeworkspace (string sservername, string sinstanceport, string sUserName, string spassword, string sversionname)
- {
- IPropertySet2 set = new Propertysetclass ();
- set. SetProperty ("Server", " ");
- set. SetProperty ("dbclient", "Oracle");
- set. SetProperty ("Instance", "sde:oracle11g:" + sinstanceport);
- set. SetProperty ("User", sUserName);
- set. SetProperty ("password", Spassword);
- set. SetProperty ("version", Sversionname);
- IWorkspaceFactory2 Class2 = new Sdeworkspacefactoryclass ();
- Try
- {
- return Class2. Open (set, 0);
- }
- catch (Exception ex)
- {
- return null;
- }
- }
Note: Although this is an example of ArcGIS engine, we need to understand some of the basics of ARCSDE, that is, we can only disconnect other users through the SDE Admin user, even if the user you are currently connected to has DBA authority. I personally infer that ESRI writes the user name to SDE at the code level, so that other users cannot connect at all, directly to the error.
So what if the user before the ArcGIS10.1 version does this?
1: Edit the ARCSDE command as a bat file and invoke it directly in C # or the Java language.
2: If you are familiar with Oracle database, of course, because ARCSDE as a database middleware, its core is to invoke the relevant functions of Oracle, so we can bypass the ARCSDE hierarchy, directly on the Oracle operation.
Note: Of course, it is not recommended for ordinary users to do so, compared with a certain risk.
We can associate the process_information with v$session under the SDE user and get the final disconnect information based on the sde_id, application name, terminal name, user name and other information obtained by the SDE command.
- sql> Select A.sde_id,a.server_id,b.sid,b.serial#,b.program,b.username,b.terminal
- From Sde.process_information A, v$session b
- where A.start_time=b.logon_time;
- sde_id server_id SID serial# program USERNAME TERMINAL
- ------ --------------------------------------- ---------- ---------- ------------------------------
- 5692 386 Sde.vshost.exe SDE WIN-HV4HFT8KPSS
- 4756 137 4713 ArcMap.exe BBB WIN-HV4HFT8KPSS
Disconnect user connections via SID and Serial#, example: Alter system kill session ' Sid,serial '; Alter system kill session ' 137,4713 ' by using the following SQL statement; Disconnect the BBB user from the ArcMap application.
ArcGIS Engine Disconnects other ARCSDE user-connected solutions