<?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: ArcSDE WorkspaceFactory Connection Error in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcsde-workspacefactory-connection-error/m-p/433178#M11740</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay, after digging around, I finally worked it out. It turns out, database connections are stored in specific locations, based on the user profile. I just added code that replaces the Database Connections prefix with the expected location of the database connection. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; Dim connection as String = "Database Connections\myGIS.sde" ' ... other stuff&amp;nbsp; Dim factoryType as Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory") Dim myWorkspaceFactory = Ctype(Activator.CreateInstance(factoryType), IWorkspaceFactory)&amp;nbsp; If connection.StartsWith("Database Connections\") Then&amp;nbsp; Dim userProfile as String = System.Environment.GetEnvironmentVariable("UserProfile")&amp;nbsp; ' for 10.0 ' Dim fileLocation As String = userProfile &amp;amp; "\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\" ' for 10.1 Dim fileLocation As String = userProfile &amp;amp; "\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\"&amp;nbsp; connection = connection.Replace("Database Connections\", fileLocation)&amp;nbsp; End If&amp;nbsp; Dim myWorkspace as IWorkspace = myWorkspaceFactory.OpenFromFile(connection, 0) ' no more error &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 25 Sep 2012 18:41:10 GMT</pubDate>
    <dc:creator>KenDoman</dc:creator>
    <dc:date>2012-09-25T18:41:10Z</dc:date>
    <item>
      <title>ArcSDE WorkspaceFactory Connection Error</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcsde-workspacefactory-connection-error/m-p/433177#M11739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Part of my addin is trying to connect to what could be a SDE connection. I'm using WorkspaceFactory.OpenfromFile to connect to the geodatabase, because the connection could be to a file geodatabase, personal geodatabase, or an sde connection. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's where my error is coming in. When I set the location of my connection file to the absolute location (C:\Users\ ... \ArcCatalog\myGIS.sde), it connects fine. But when I set it to "Database Connections\myGIS.sde", which is the location I get when I use the ArcCatalog dialog to browse to the geodatabase, the connection throws an error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a way to get the file location for the database connection file programmatically? I want to use OpenFromFile because I don't want to handle user names and passwords, and because I can open other geodatabases with the same code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's an edited snippet of my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; ' code works when connection = "C:\Users\ ... \ArcCatalog\myGIS.sde"&amp;nbsp; Dim connection as String = "Database Connections\myGIS.sde"&amp;nbsp; Dim myWorkspace as IWorkspace Dim factoryType as Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory") Dim myWorkspaceFactory = Ctype(Activator.CreateInstance(factoryType), IWorkspaceFactory)&amp;nbsp; myWorkspace = myWorkspaceFactory.OpenFromFile(connection, 0) ' here is where I get the error. &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Sep 2012 14:53:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcsde-workspacefactory-connection-error/m-p/433177#M11739</guid>
      <dc:creator>KenDoman</dc:creator>
      <dc:date>2012-09-25T14:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: ArcSDE WorkspaceFactory Connection Error</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcsde-workspacefactory-connection-error/m-p/433178#M11740</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay, after digging around, I finally worked it out. It turns out, database connections are stored in specific locations, based on the user profile. I just added code that replaces the Database Connections prefix with the expected location of the database connection. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; Dim connection as String = "Database Connections\myGIS.sde" ' ... other stuff&amp;nbsp; Dim factoryType as Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory") Dim myWorkspaceFactory = Ctype(Activator.CreateInstance(factoryType), IWorkspaceFactory)&amp;nbsp; If connection.StartsWith("Database Connections\") Then&amp;nbsp; Dim userProfile as String = System.Environment.GetEnvironmentVariable("UserProfile")&amp;nbsp; ' for 10.0 ' Dim fileLocation As String = userProfile &amp;amp; "\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\" ' for 10.1 Dim fileLocation As String = userProfile &amp;amp; "\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\"&amp;nbsp; connection = connection.Replace("Database Connections\", fileLocation)&amp;nbsp; End If&amp;nbsp; Dim myWorkspace as IWorkspace = myWorkspaceFactory.OpenFromFile(connection, 0) ' no more error &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Sep 2012 18:41:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcsde-workspacefactory-connection-error/m-p/433178#M11740</guid>
      <dc:creator>KenDoman</dc:creator>
      <dc:date>2012-09-25T18:41:10Z</dc:date>
    </item>
  </channel>
</rss>

