Select to view content in your preferred language

SQL Server backed FeatureLayer added to the map has display issues

430
2
08-22-2023 01:43 AM
ViktorSafar
Occasional Contributor II

I am adding a FeatureLayer to the current map. The FL is backed by table in a SQL Server database. This is how I add the FL:

 

 

var connProps = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
{
	Instance = "my remote instance",
	Database = "dbname",
	User = "****",
	Password = "****",
	AuthenticationMode = AuthenticationMode.DBMS,
};

var gdb = new Geodatabase(connProps);

CIMSqlQueryDataConnection connection = new CIMSqlQueryDataConnection()
{
	WorkspaceConnectionString = gdb.GetConnectionString(),
	GeometryType = esriGeometryType.esriGeometryPolygon,
	OIDFields = "OBJECTID",
	Srid = "32632",
	SqlQuery = "select * from [dbname].[fb_gdb].[TRAININGAREA]",
	Dataset = "TrainingAreas",
	DatasetType = esriDatasetType.esriDTFeatureClass
};

var layerParams = new LayerCreationParams(connection )
{
	Name = Constants.LayerTrainingAreasName
};

var layer = LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams, MapView.Active.Map);

 

 

 

The layer contains polygons and I added a renderer with a pink outline. During panning/zooming the features are not drawn well - sometimes completely missing, sometimes a chunk of the outline is missing:

ViktorSafar_0-1692693498887.png

If I add the same layer via Pro's Catalog -> Databases -> Add connection, and then drag and drop the layer into the map, it behaves correctly.

Any ideas?

I have tried to add the connection to the Catalog via code to see if that helps but was unable to figure out how to do that 

 

 

Project.Current.AddItem( how do I make an IProjectItem out of the GDB or the connection?? )

 

 

 

0 Kudos
2 Replies
GKmieliauskas
Esri Regular Contributor
0 Kudos
ViktorSafar
Occasional Contributor II

Thanks, I indeed managed to add the item to the Catalog. However, it gets more complicated.

The item that can be added to the Catalog has to exist on disk (ItemType = PathItem). For that we need to create a connection file and save it to the disk. There is no .NET interface to build the connection file so the creation of the connection has to go via Python: via Geoprocessing.ExecuteToolAsync("management.CreateDatabaseConnection", @params) 

... and that brings us to yet another problem that I describe here: https://community.esri.com/t5/arcgis-pro-sdk-questions/management-createdatabaseconnection-takes-2/m...

 

For those interested in the code

internal static object[] GetSdeFileParams()
{
	var out_folder_path = Project.Current.HomeFolderPath;
	var out_name = SDEConnectionName;
	var database_platform = "SQL_SERVER";
	var instance = "XXX";
	var account_authentication = "DATABASE_AUTH";
	var username = "USERID";
	var password = "YYY";
	var save_user_pass = "SAVE_USERNAME";
	var database = "ZZZ";

	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);

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