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 -


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:

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)
            string connStr = "SERVER=server;INSTANCE=5151;VERSION=version;USER=user;PASSWORD=pwd";

        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.