ThinkGeo.com    |     Documentation    |     Premium Support

SqliteFeatureLayer - Exception on Open

MapSuite Team,

When using the SQLiteConnection the feature layer is created, however on the Open an exception occurs. When using the actual connection string the Open does not encounter an exception.

The following Open results in the exception – “Data Source cannot be empty. Use :memory: to open an in-memory database”

TheSqliteFeatureLayer = new SqliteFeatureLayer(anSQLiteConnection, “TableName”, “Id”, “geometry”);
TheSqliteFeatureLayer.Open();

The following Open does not result in an exception:

TheSqliteFeatureLayer = new SqliteFeatureLayer(anSQLiteConnection.ConnectionString, “TableName”, “Id”, “geometry”);
TheSqliteFeatureLayer.Open();

The ConnectionString in both cases is:

Data Source=C:\OriStar\Chicago\OriStarVisionMapSuite\MapSQLite\BikeRoutes.sqlite;Version=3;

If the exception is caught and ignored the layer is actually opened and any other actions on the layer are successful.

Thanks,
Dennis

Message=Data Source cannot be empty. Use :memory: to open an in-memory database

System.Data.SQLite
at System.Data.SQLite.SQLiteConnection.Open()
at ThinkGeo.MapSuite.Layers.SqliteFeatureSource.GetColumnNames(String connectionString, String tableName)
at ThinkGeo.MapSuite.Layers.SqliteValidatorHelper.CheckFeatureIdAndGeometryColumn(String connectionString, String tableName, String featureIdColumn, String geometryColumnName)
at ThinkGeo.MapSuite.Layers.SqliteFeatureSource.OpenCore()
at ThinkGeo.MapSuite.Layers.FeatureSource.Open()
at ThinkGeo.MapSuite.Layers.FeatureLayer.OpenCore()
at ThinkGeo.MapSuite.Layers.Layer.Open()
at OriStarFileGeoDatabase.GeneralMethods.PopulateDatabaseCollectionSQLiteTables(SQLiteConnection TheDbConnection, clsGeoDatabaseItem& oGeoDatabaseItem) in C:\OriStarMappingIncMapSuiteV10Secondary\OriStarFileGeoDatabase\TheGeneralMethods.cs:line 473

Hi Dennis,

Thanks for your information, that’s should be a bug.

Our developer had fixed it, please get this package when it’s available in Nuget: https://www.nuget.org/packages/ThinkGeo.MapSuite.Layers.Sqlite/11.0.0-beta012

And please let us know whether it solved your problem.

Regards,

Ethan

Ethan,

The beta012 version is not yet available.

Dennis

Hi Dennis,

You can get it now, the 012 is available.

Regards,

Ethan

hi Ethan,

Thanks for the beta012 version as the Open does not encounter an exception.

However, GetAllFeatures now encounters an exception as shown below. The FeatureSource is open, but the exception states that it is not.

When the following is used everything works fine:

TheSqliteFeatureLayer = new SqliteFeatureLayer(anSQLiteConnection.ConnectionString, "TableName", "Id", "geometry");

Thanks,
Dennis

Unable to GetAllFeatures
TableName=BikeRoutes
System.InvalidOperationException: Database is not open
at System.Data.SQLite.SQLiteCommand.InitializeForReader()
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteReader()
at ThinkGeo.MapSuite.Layers.SqliteFeatureSource.GetAllFeaturesCore(IEnumerable1 columnNames) at ThinkGeo.MapSuite.Layers.FeatureSource.GetAllFeatures(IEnumerable1 returningColumnNames)
at ThinkGeo.MapSuite.Layers.FeatureSource.GetAllFeaturesCore(IEnumerable1 returningColumnNames, Int32 startIndex, Int32 takeCount) at ThinkGeo.MapSuite.Layers.FeatureSource.GetAllFeatures(IEnumerable1 returningColumnNames, Int32 startIndex, Int32 takeCount)
at ThinkGeo.MapSuite.Layers.FeatureSource.GetAllFeatures(ReturningColumnsType returningColumnTypes, Int32 startIndex, Int32 takeCount)
at OriStarFileGeoDatabase.DatabaseTableFeatureData.LoadDatabaseTableFeatureDataCollection(clsGeoDatabaseTableItem& oGeoDatabaseTableItem) in C:\OriStarMappingIncMapSuiteV10Secondary\OriStarFileGeoDatabase\cfDatabaseTableFeatureData.cs:line 288

Hi Dennis,

That’s because if you passed in the SQLiteConnection as paramter, you should want to open it at first.

We cannot open it again because it will throw exception if you had opened that.

And it looks SQLiteConnection don’t have a status flag to know whether it had been opened.

So I think you should want to modify your code like this:

        var TheSqliteFeatureLayer = new SqliteFeatureLayer(connection, "table_name", "id", "geometry");            
        connection.Open();            
        TheSqliteFeatureLayer.Open();
        Collection<Feature> fs = TheSqliteFeatureLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);

Wish that’s helpful.

Regards,

Ethan

Ethan,

Thanks much for the tip, it works now.

Dennis

Hi Dennis,

I am glad to hear that’s helpful.

Regards,

Ethan