Select to view content in your preferred language

SQL Server backed FeatureLayer added to the map has display issues

08-22-2023 01:43 AM
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:


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
Esri Regular Contributor
0 Kudos
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:


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[]

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;
0 Kudos