ArcGIS Pro CoreHost eGDB connection error: The gsrvr dll for a direct connection could not be loaded

281
2
08-07-2020 02:28 PM
MariusRocher
New Contributor

I have an ArcGIS Pro core host application that happily connects to a file GDB

targetGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(this.gdbTargetConnrection, UriKind.Absolute)));

 

, BUT as soon as I switch to connect to a enterprise geodatabase .sde file

targetGeodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri(this.gdbTargetConnrection, UriKind.Absolute)));

                where this.gdbTargetConnrection = ‘C:\DeleteMe\SDE\xx@xxxxxxx.sde’ an Oracle 11g geodatabase 

I get the following error:

ArcGIS.Core.Data.GeodatabaseEnterpriseException: The gsrvr dll for a direct connection could not be loaded. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80050144

   at ArcGIS.Core.Internal.IGeodatabaseIOP.Geodatabase_OpenFromEnterpriseGeodatabase(String path)

   at ArcGIS.Core.Data.GeodatabaseUtil.OpenDatastore(String path)

   --- End of inner exception stack trace ---

   at ArcGIS.Core.Data.GeodatabaseUtil.OpenDatastore(String path)

   at ArcGIS.Core.Data.Geodatabase.Open(Uri uri)

   at ArcGIS.Core.Data.Geodatabase..ctor(DatabaseConnectionFile databaseConnectionFile)

   at SSP.MLGW.Server.AnnotationSync.AnnotationSyncProcessor.Go() in

Code snippet:

using (var gdbTarget = new Geodatabase(new DatabaseConnectionFile(new Uri(@"C:\DeleteMe\SDE\xx@xxxxxxx.sde", UriKind.Absolute))))
{

      ......

}

Using a DatabaseConnectionProperties instead of a DatabaseConnectionFile yield the same error.

I have Pro 2.6 installed.

Using ArcGIS Pro or ArcCatalog I can connect via C:\DeleteMe\SDE\xx@xxxxxxx.sde without issue, so we know the Oracle client is installed and working.

 

Any help would be greatly appreciated.

0 Kudos
2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

i just tried the following code using Pro 2.6 without any problems:  

//Call Host.Initialize before constructing any objects from ArcGIS.Core
Host.Initialize();
try
{
	var targetGeodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri(@"C:\Data\FeatureTest\sdk5.esri.com.sde", UriKind.Absolute)));
	Console.WriteLine("Done");
}
catch (Exception ex)
{
	Console.Error.WriteLine($@"Error: {ex}");
}

In order to debug which Dll is missing, you can try to add the following code (you can also copy this from this sample: CoreHost Resolve Assembly

Just replace the path to the .sde file.

//[STAThread] must be present on the Application entry point
[STAThread]
static void Main(string[] args)
{
	//Resolve ArcGIS Pro assemblies.
	AppDomain currentDomain = AppDomain.CurrentDomain;
	currentDomain.AssemblyResolve += new ResolveEventHandler(ResolveProAssemblyPath);

	RunLogic();
}

static void RunLogic()
{
	//Call Host.Initialize before constructing any objects from ArcGIS.Core
	Host.Initialize();
	try
	{
		var targetGeodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri(@"C:\Data\FeatureTest\sdk5.esri.com.sde", UriKind.Absolute)));
		Console.WriteLine("Done");
	}
	catch (Exception ex)
	{
		Console.Error.WriteLine($@"Error: {ex}");
	}
}

static Assembly ResolveProAssemblyPath(object sender, ResolveEventArgs args)
{
	//Get path of Pro installation from registry 
	var arcgisProPath = GetInstallDirAndVersionFromReg().Item1;
	string ProNotFound = @"ArcGIS Pro is not installed.";
	if (string.IsNullOrEmpty(arcgisProPath)) throw new InvalidOperationException(ProNotFound);
	string assemblyPath = Path.Combine(arcgisProPath, "bin", new AssemblyName(args.Name).Name + ".dll");
	if (!File.Exists(assemblyPath)) return null;
	Assembly assembly = Assembly.LoadFrom(assemblyPath);
	return assembly;
}

/// <summary>
/// Get the ArcGIS Pro install location from the registry.
/// </summary>
/// <returns></returns>
private static Tuple<string, string> GetInstallDirAndVersionFromReg()
{
	string regPath = @"SOFTWARE\ESRI\ArcGISPro";
	string installMissing = @"Install location of ArcGIS Pro cannot be found. Please check your registry for {0}";
	string versionMissing = @"Version of ArcGIS Pro cannot be determined. Please check your registry for {0}.";
	string err1 = string.Format(installMissing, $@"HKLM\{regPath}\InstallDir");
	string err2 = string.Format(versionMissing, $@"HKLM\{regPath}\Version");


	string path = "";
	string version = "";
	try
	{
		RegistryKey localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
		RegistryKey esriKey = localKey.OpenSubKey(regPath);

		if (esriKey == null)
		{
			localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, RegistryView.Registry64);
			esriKey = localKey.OpenSubKey(regPath);
		}
		if (esriKey == null)
		{
			//this is an error
			throw new System.InvalidOperationException(err1);
		}
		path = esriKey.GetValue("InstallDir") as string;
		if (path == null || path == string.Empty)
			//this is an error
			throw new InvalidOperationException(err1);

		version = esriKey.GetValue("Version") as string;
		if (version == null || version == string.Empty)
			//this is an error
			throw new InvalidOperationException(err2);
	}
	catch (InvalidOperationException ie)
	{
		//this is ours
		throw ie;
	}
	catch (Exception ex)
	{
		throw new System.Exception(err1, ex);
	}
	return new Tuple<string, string>(path, version);
}
0 Kudos
MariusRocher
New Contributor

Wolfgang

Running the tool as administrator mitigates the problem.    The underlying cause is therefore likely permissions to ~\Program Files\ArcGIS\Pro\binPro.

Thank you for your help.

Marius

0 Kudos