ThinkGeo.com    |     Documentation    |     Premium Support

Problem with SqlServerFeatureLayer after upgrading to 14.5.0

Today we upgraded to TG 14.5.0 and when I try to add a SqlServerFeatureLayer I get an exception from the method GetFirstGeometryType(). We did make the call to the Open() method before calling GetFirstGeometryType(). Here is the exception:

Exception Source: ThinkGeo.Core Exception Type: System.InvalidOperationException Exception Message: The FeatureSource is not open. Please call the Open method before calling this method. Exception Target Site: CheckFeatureSourceIsOpen

---- Stack Trace ----
ThinkGeo.Core.ValidatorHelper.CheckFeatureSourceIsOpen(isOpen As Boolean)
GeoSuite.exe: N 00070
ThinkGeo.Core.SqlServerFeatureSource.GetFirstGeometryType()
GeoSuite.exe: N 00064
MapUtilities.CustomSQLFeatureLayer.get_ShapeType()
CustomSQLFeatureLayer.vb: line 0400, col 09, IL 0037
MapUtilities.CustomSQLFeatureLayer.SetDefaultDisplayStyle(oLayerStyle As Style)
CustomSQLFeatureLayer.vb: line 0554, col 09, IL 0003
MapUtilities.VB$StateMachine_5_AddSQLFeatureLayers.MoveNext()
LayerUtils.vb: line 0357, col 17, IL 3123

Can you tell me what the problem is?

Thanks!

Steve

Hi Steve,

We upgraded ThinkGeo.SqlServer from System.Data.SqlClient to Microsoft.Data.SqlClient (v6.1.2). Starting with v4.0 of that package, connections on .NET 6+ targets default to Encrypt=Mandatory, meaning TLS encryption and certificate validation are now required. The old System.Data.SqlClient defaulted to Encrypt=Optional, so connection strings that worked before may now fail silently when connecting to a SQL Server instance without a trusted TLS certificate.

To work it around, just add TrustServerCertificate=True; to your SQL Server connection string:
Server=myserver;Database=mydb;Trusted_Connection=True;TrustServerCertificate=True;

or pull the latest beta011, in which we automatically apply TrustServerCertificate=True when your connection string doesn’t already specify it, so existing connection strings will continue to work without modification.

Why the error is misleading:

When the connection fails during Open(), the exception is currently stored internally rather than surfaced immediately, so instead of seeing the real connection error you get “The FeatureSource is not open” later when you call GetFirstGeometryType(). We’ll be improving exception propagation in Open() so the real error is visible right away.

Thanks,
Ben