ArcGIS Engine Disconnects other ARCSDE user-connected solutions

Source: Internet
Author: User

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.

  1. C:\users\li>sdemon-o Kill
  2. ESRI ArcSDE System Monitor Utility Fri 29 14:50:02 2014
  3. -------------------------------------------------------------------------
  4. Sdemon-o kill-t {all | <pid>} [-U <db_user_name>] [-P <db_admin_password
  5. ;]
  6. {[-I <service>] [-S <server_name>] | [-H <sde_directory>]}
  7. [-D <database>] [-N]
  8. Sdemon-h
  9. 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.

  1. Public static void Test ()
  2. {
  3. Try
  4. {
  5. Iworkspace PWS = getsdeworkspace ("localhost", "LOCALHOST/ORCL", "SDE", "SDE", "SDE") .  DEFAULT ");
  6. IDatabaseConnectionInfo4 pdcinfo = PWS as IDatabaseConnectionInfo4;
  7. Ienumuserinfo penumusers = pdcinfo.connectedusers;
  8. Iuserinfo puser = Penumusers.next ();
  9. int Psessionid; //Get SessionID of connected users
  10. string susername = ""; Connect user name
  11. string sclientname = ""; Connect user's machine name
  12. string sconnetiontime = ""; Connect user's Start connection time
  13. While (puser! = null)
  14. {
  15. if (!puser.isownconnection)
  16. {
  17. Psessionid = Puser.sessionid;
  18. sUserName = Puser.name;
  19. Sclientname = Puser.clientname;
  20. Sconnetiontime = PUser.ConnectionTime.ToString ();
  21. //Disconnect users via user's SessionID
  22. Pdcinfo.disconnectuser (Psessionid);
  23. }
  24. Puser = Penumusers.next ();
  25. }
  26. }
  27. catch (Exception e)
  28. { }
  29. }
  30. public static Iworkspace getsdeworkspace (string sservername, string sinstanceport, string sUserName, string spassword, string sversionname)
  31. {
  32. IPropertySet2 set = new Propertysetclass ();
  33. set.  SetProperty ("Server", " ");
  34. set.  SetProperty ("dbclient", "Oracle");
  35. set.  SetProperty ("Instance", "sde:oracle11g:" + sinstanceport);
  36. set.  SetProperty ("User", sUserName);
  37. set.  SetProperty ("password", Spassword);
  38. set.  SetProperty ("version", Sversionname);
  39. IWorkspaceFactory2 Class2 = new Sdeworkspacefactoryclass ();
  40. Try
  41. {
  42. return Class2.  Open (set, 0);
  43. }
  44. catch (Exception ex)
  45. {
  46. return null;
  47. }
  48. }

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.

  1. sql> Select A.sde_id,a.server_id,b.sid,b.serial#,b.program,b.username,b.terminal
  2. From Sde.process_information A, v$session b
  3. where A.start_time=b.logon_time;
  4. sde_id server_id SID serial# program USERNAME TERMINAL
  5. ------ --------------------------------------- ---------- ---------- ------------------------------
  6. 5692 386 Sde.vshost.exe SDE WIN-HV4HFT8KPSS
  7. 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

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.