1

I'm trying to make a little utility to generate encrypted passwords for MSD files (change the XML inside the zip). I found this example online, but I'm not familiar with esri's API, so I'm not sure how to use IWorkspaceName2::ConnectionString as suggested in the following documentation link -

http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeodatabase/IWorkspaceFactory2_Example.htm

OpenFromString actually makes a connection, which is not ideal for my purposes, so if that can be ommited entirely and get the ConnectionString property value from the IWorkspaceName2 that would do it. I wasn't able to find out how to create a IWorkspaceName2 object so that's what I'm looking for, either c# or vb.net.

string connectionString = "SERVER=myServer;DATABASE=sde;INSTANCE=5151;USER=Editor;PASSWORD=Editor;VERSION=SDE.DEFAULT"
IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2)new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
return workspaceFactory.OpenFromString(connectionString, 0);

//A better solution is to use IWorkspaceName2::ConnectionString which returns an encrypted password:
ENCRYPTED_PASSWORD=0001d2756fc3e1b91529;SERVER=myServer;INSTANCE=5151;USER=Editor;VERSION=SDE.DEFAULT`
1

Works with this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;

namespace SDEtest
{
    class Program
    {
        static void Main(string[] args)
        {
            ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
            string connStr = "SERVER=server;INSTANCE=5151;VERSION=version;USER=user;PASSWORD=pwd";
            Console.WriteLine(GetConnStr(connStr));
            Console.ReadLine();
        }

        static string GetConnStr(string ConnectionString)
        {
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
            IWorkspaceFactory2 workspaceFactory2 = (IWorkspaceFactory2)Activator.CreateInstance(factoryType);
            IWorkspace ws = workspaceFactory2.OpenFromString(ConnectionString, 0);

            IDataset dataset = (IDataset)ws;

            IWorkspaceName2 name2 = (IWorkspaceName2)dataset.FullName;

            return name2.ConnectionString;
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.