<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Get database username from current edit workspace/session in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145349#M3800</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You may have more that one connection in your map for different layers.&amp;nbsp; Find the layer you want, get its featureclass, from that get its workspace (from Idataset), cast workspace to IDatabaseConnectionInfo2.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Jul 2011 16:12:56 GMT</pubDate>
    <dc:creator>AlexanderGray</dc:creator>
    <dc:date>2011-07-07T16:12:56Z</dc:date>
    <item>
      <title>Get database username from current edit workspace/session</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145348#M3799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm looking to get the username from the current geodatabase connection so that I can stamp modifications to features with the current time and username.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone know what interface I would be able to use in an Add-In to get this information?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2011 13:13:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145348#M3799</guid>
      <dc:creator>JordanMacDonald</dc:creator>
      <dc:date>2011-07-07T13:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Get database username from current edit workspace/session</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145349#M3800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You may have more that one connection in your map for different layers.&amp;nbsp; Find the layer you want, get its featureclass, from that get its workspace (from Idataset), cast workspace to IDatabaseConnectionInfo2.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2011 16:12:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145349#M3800</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2011-07-07T16:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get database username from current edit workspace/session</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145350#M3801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Assuming you are in an edit session, you can use IWorkspace.ConnectionProperties to get this information.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;E.g. MessageBox.Show(m_editor.EditWorkspace.ConnectionProperties.GetProperty("user").ToString());&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Take a look at the example in IPropertySet for the other connection strings.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2011 17:52:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145350#M3801</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2011-07-07T17:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Get database username from current edit workspace/session</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145351#M3802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As an alternative approach in addition to the suggestions already made, have you thought about returning the user account from the Windows Authentication (WindowsIdentity)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I use this in ALL of my ArcGIS applications because it's great to be able to throw around that user credential in many different components (for db logon, CrystalReporting, etc...).&amp;nbsp; Anyway, below is a bit of code sampe that you might be able to use.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Imports System.Data
Imports System.Data.SqlClient
Imports System.Security.Principal
Imports System

Public Class Form1

&amp;nbsp;&amp;nbsp; Private m_User As String


Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

&amp;nbsp;&amp;nbsp; Dim logonToken As IntPtr = LogonUser()
&amp;nbsp;&amp;nbsp; m_User = GetUserName(logonToken)

'Now you can use the m_User in your app for reporting/doing stuff with the current user that is
'logged into with Windows Authentication

End Sub

Private Function LogonUser() As IntPtr
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim accountToken As IntPtr = WindowsIdentity.GetCurrent().Token
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return accountToken
End Function

Function GetUserName(ByVal logonToken As IntPtr) As String
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim windowsIdentity As New WindowsIdentity(logonToken)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim parts() As String = Split(windowsIdentity.Name, "\")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim username As String = parts(1)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return username

End Function&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:56:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145351#M3802</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T07:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Get database username from current edit workspace/session</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145352#M3803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;As an alternative approach in addition to the suggestions already made, have you thought about returning the user account from the Windows Authentication (WindowsIdentity)?&lt;BR /&gt;&lt;BR /&gt;I use this in ALL of my ArcGIS applications because it's great to be able to throw around that user credential in many different components (for db logon, CrystalReporting, etc...).&amp;nbsp; Anyway, below is a bit of code sampe that you might be able to use.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Imports System.Data
Imports System.Data.SqlClient
Imports System.Security.Principal
Imports System

Public Class Form1

&amp;nbsp;&amp;nbsp; Private m_User As String


Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

&amp;nbsp;&amp;nbsp; Dim logonToken As IntPtr = LogonUser()
&amp;nbsp;&amp;nbsp; m_User = GetUserName(logonToken)

'Now you can use the m_User in your app for reporting/doing stuff with the current user that is
'logged into with Windows Authentication

End Sub

Private Function LogonUser() As IntPtr
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim accountToken As IntPtr = WindowsIdentity.GetCurrent().Token
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return accountToken
End Function

Function GetUserName(ByVal logonToken As IntPtr) As String
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim windowsIdentity As New WindowsIdentity(logonToken)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim parts() As String = Split(windowsIdentity.Name, "\")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim username As String = parts(1)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return username

End Function&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;An easier way to do this in .NET is System.Environment.UserName.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:56:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145352#M3803</guid>
      <dc:creator>NeilClemmons</dc:creator>
      <dc:date>2021-12-11T07:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Get database username from current edit workspace/session</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145353#M3804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Windows user name is fine if you are using OS authentication in your connection.&amp;nbsp; If not, this won't tell you what user is connected to the database.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2011 12:35:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/get-database-username-from-current-edit-workspace/m-p/145353#M3804</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2011-07-12T12:35:02Z</dc:date>
    </item>
  </channel>
</rss>

