# SqliteFeatureLayer - Exception on Open

**URL:** <https://community.thinkgeo.com/t/sqlitefeaturelayer-exception-on-open/9547>\
**Category:** WPF\
**Created:** [July 10, 2019, 2:10pm UTC](https://community.thinkgeo.com/t/sqlitefeaturelayer-exception-on-open/9547 "2019-07-10T14:10:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dennis](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/e56c9b/32.png) [@Dennis](https://community.thinkgeo.com/u/Dennis)\
**Post date:** [July 10, 2019, 2:10pm UTC](https://community.thinkgeo.com/t/sqlitefeaturelayer-exception-on-open/9547/1 "2019-07-10T14:10:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [July 11, 2019, 7:47am UTC](https://community.thinkgeo.com/t/sqlitefeaturelayer-exception-on-open/9547/2 "2019-07-11T07:47:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dennis](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/e56c9b/32.png) [@Dennis](https://community.thinkgeo.com/u/Dennis)\
**Post date:** [July 11, 2019, 7:10pm UTC](https://community.thinkgeo.com/t/sqlitefeaturelayer-exception-on-open/9547/3 "2019-07-11T19:10:59Z")

</div>

Ethan,

The beta012 version is not yet available.

Dennis

 ![](https://community.thinkgeo.com/uploads/default/original/3X/6/c/6c0cc009021f74fe6c3a7057113b77303eeaaf70.png)

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [July 12, 2019, 9:01am UTC](https://community.thinkgeo.com/t/sqlitefeaturelayer-exception-on-open/9547/4 "2019-07-12T09:01:50Z")

</div>

Hi Dennis,

You can get it now, the 012 is available.

Regards,

Ethan

---

<div class="post-metadata">

**Author:** ![Dennis](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/e56c9b/32.png) [@Dennis](https://community.thinkgeo.com/u/Dennis)\
**Post date:** [July 12, 2019, 2:32pm UTC](https://community.thinkgeo.com/t/sqlitefeaturelayer-exception-on-open/9547/5 "2019-07-12T14:32:28Z")

</div>

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

 ![](https://community.thinkgeo.com/uploads/default/original/3X/c/a/ca8b82817252a0ab1dc5e57a8693cf3b71c339c4.png)

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(IEnumerable`1 columnNames) at ThinkGeo.MapSuite.Layers.FeatureSource.GetAllFeatures(IEnumerable`1 returningColumnNames)  
at ThinkGeo.MapSuite.Layers.FeatureSource.GetAllFeaturesCore(IEnumerable`1 returningColumnNames, Int32 startIndex, Int32 takeCount) at ThinkGeo.MapSuite.Layers.FeatureSource.GetAllFeatures(IEnumerable`1 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

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [July 15, 2019, 4:56am UTC](https://community.thinkgeo.com/t/sqlitefeaturelayer-exception-on-open/9547/6 "2019-07-15T04:56:10Z")

</div>

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.

 ![](https://community.thinkgeo.com/uploads/default/original/3X/7/4/74078dd96fafb5f773626d74f2f7e948713d575e.png)

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

---

<div class="post-metadata">

**Author:** ![Dennis](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/e56c9b/32.png) [@Dennis](https://community.thinkgeo.com/u/Dennis)\
**Post date:** [July 15, 2019, 2:57pm UTC](https://community.thinkgeo.com/t/sqlitefeaturelayer-exception-on-open/9547/7 "2019-07-15T14:57:18Z")

</div>

Ethan,

Thanks much for the tip, it works now.

Dennis

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [July 16, 2019, 3:16am UTC](https://community.thinkgeo.com/t/sqlitefeaturelayer-exception-on-open/9547/8 "2019-07-16T03:16:42Z")

</div>

Hi Dennis,

I am glad to hear that’s helpful.

Regards,

Ethan
