How to get SQL server name from PDM API?

I have a PDM addin that uses some SQL queries directly to the database.  I am trying to find a way to get the server name itself from the API, so I don't have to hardcode it in to the connection string.  I didn't see anything useful in IEdmVault(n).  Is there some easy way?  As a last resort i could probably read C:\\{vault}\\desktop.ini and pick thru it.

SolidworksApi macros
Answers 2
LY
LY 2018-04-17 Best Answer

Use the registry.

<p>public static string GetServerName(string vaultName)</p><p>        {</p><p>            if (string.IsNullOrEmpty(vaultName))</p><p>                return string.Empty;</p><p>            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey($@"SOFTWARE\SolidWorks\Applications\PDMWorks Enterprise\Databases\{vaultName}", false);</p><p>            if (key != null)</p><p>            {</p><p>                return key.GetValue("DBServer").ToString();</p><p>            }</p><p>            return null;</p><p>        }</p><p>        public static string GetDatabaseName(string vaultName)</p><p>        {</p><p>            if (string.IsNullOrEmpty(vaultName))</p><p>                return string.Empty;</p><p>            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey($@"SOFTWARE\SolidWorks\Applications\PDMWorks Enterprise\Databases\{vaultName}", false);</p><p>            if (key != null)</p><p>            {</p><p>                return key.GetValue("DbName").ToString();</p><p>            }</p><p>            return null;</p><p>        }</p>
TS
TS 2018-04-18

Thanks Lee!