Select to view content in your preferred language

management.CreateDatabaseConnection takes 2 minutes

214
0
09-05-2023 06:35 AM
ViktorSafar
Occasional Contributor II

I have now run this about a 100 times and am getting consistent results. Call for management.CreateDatabaseConnection via Geoprocessing.ExecuteToolAsync takes minimum 2 minutes, sometimes even 3 minutes.

internal static object[] GetSdeFileParams()
{
	var out_folder_path = Project.Current.HomeFolderPath;
	var out_name = "connection.sde";
	var database_platform = "SQL_SERVER";
	var instance = "<some>";
	var account_authentication = "DATABASE_AUTH";
	var username = "sa";
	var password = "<some>";
	var save_user_pass = "SAVE_USERNAME";
	var database = "<some>";

	return new object[]
			{
				out_folder_path,
				out_name,
				database_platform,
				instance,
				account_authentication,
				username,
				password,
				save_user_pass,
				database
			};
}


var p = GetSdeFileParams();
var va = Geoprocessing.MakeValueArray(p);
IGPResult result = await Geoprocessing.ExecuteToolAsync("management.CreateDatabaseConnection", va);

 

I am doing this because I want to add a SQL connection to the Catalog:

await QueuedTask.Run(() =>
{         
	var sdeFilePath = System.IO.Path.Combine(Project.Current.HomeFolderPath, "connection.sde");
	var item = ItemFactory.Instance.Create(sdeFilePath);
	var gdbitem = item as GDBProjectItem;
	Project.Current.AddItem(gdbitem);
});

 

So that I can later add layers from it:

 

return QueuedTask.Run(() =>
{
	var item = GetGDBProjectItem(); 
	var gdb = item.GetDatastore() as Geodatabase;
	using var fc = gdb.OpenDataset<FeatureClass>(gdbFeatureClassName);
	var layerParams = new FeatureLayerCreationParams(fc) { Name = displayName, MapMemberIndex = _bottom };
	var layer = LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams, MapView.Active.Map);
	layer.SetVisibility(isVisible);
	layer.SetRenderer(renderer);
});

...

private static GDBProjectItem GetGDBProjectItem()
{
    return Project.Current.GetItems<GDBProjectItem>().FirstOrDefault(x => ((GDBProjectItem)x).Name == "connection.sde");
}

 

On top of that I am getting inconsistent results when timing other tools:

  • CreateFeatureClass - calls the management.CreateFeatureClass function, same parameters every time
  • AddFeatureLayerFromDatabaseConnection - calls the method shown above that adds the feature layer from the db connection pulled from the project items

 

CreateFeatureClass Time taken: 3.9652852 seconds
CreateFeatureClass Time taken: 5.6289978 seconds
CreateFeatureClass Time taken: 1.1572572 seconds
CreateDatabaseConnection Time taken: 122.6314865 seconds
CreateFeatureClass Time taken: 1.7061173 seconds
CreateFeatureClass Time taken: 2.7112893 seconds
AddFeatureLayerFromDatabaseConnection Time taken: 0.0033139 seconds
CreateFeatureClass Time taken: 10.8855607 seconds
CreateFeatureClass Time taken: 1.9875031 seconds

 

 

CreateFeatureClass Time taken: 2.8461999 seconds
CreateFeatureClass Time taken: 1.2559917 seconds
CreateFeatureClass Time taken: 1.2581186 seconds
CreateDatabaseConnection Time taken: 117.7707755 seconds
CreateFeatureClass Time taken: 0.6275694 seconds
CreateFeatureClass Time taken: 0.6645731 seconds
CreateFeatureClass Time taken: 0.7390637 seconds
AddFeatureLayerFromDatabaseConnection Time taken: 0.0016465 seconds
CreateFeatureClass Time taken: 7.3610697 seconds
CreateFeatureClass Time taken: 7.3479213 seconds
CreateFeatureClass Time taken: 1.3977875 seconds
AddFeatureLayerFromDatabaseConnection Time taken: 0.0009356 seconds
AddFeatureLayerFromDatabaseConnection Time taken: 0.0003054 seconds
CreateFeatureClass Time taken: 2.4290515 seconds
CreateFeatureClass Time taken: 2.2437601 seconds
CreateFeatureClass Time taken: 2.1025431 seconds
AddFeatureLayerFromDatabaseConnection Time taken: 0.0003309 seconds
AddFeatureLayerFromDatabaseConnection Time taken: 0.00035 seconds
AddFeatureLayerFromDatabaseConnection Time taken: 0.0003141 seconds
CreateFeatureClass Time taken: 3.6931787 seconds
CreateFeatureClass Time taken: 3.5080202 seconds
CreateFeatureClass Time taken: 3.4815227 seconds
Done

 

I can live with 7 seconds, but it is very hard to live with 2 or 3 minutes. If I add the same connection manually via Pro's GUI, it is instant.

 

0 Kudos
0 Replies