Efcore: SpatialiteLoader throws SqliteException: 'SQLite Error 1: 'not authorized'.'

Created on 17 Jan 2019  路  2Comments  路  Source: dotnet/efcore

Might be related to #14402 (not calling SpatialiteLoader.Load(connection); results in exception SqliteException: 'SQLite Error 1: 'no such function: InitSpatialMetaData'.' as EF Core fails to load Spatialite itself). As it was suggested in the related issue, I've tried loading Spatialite manually, which results in the exception below.

Exception message: SQLite Error 1: 'not authorized'.
Stack trace: 
   at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()
   at Microsoft.EntityFrameworkCore.Infrastructure.SpatialiteLoader.Load(DbConnection connection)
   at Playground.EfCore.Sqlite.Program.Main(String[] args) in E:\git\Playground.EfCore.Sqlite\Playground.EfCore.Sqlite\Program.cs:line 16

Steps to reproduce

Complete code listing is included below:

```c#
using System;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Playground.EfCore.Sqlite
{
class Program
{
static void Main(string[] args)
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
SpatialiteLoader.Load(connection); // throws Microsoft.Data.Sqlite.SqliteException: 'SQLite Error 1: 'not authorized'.'

        var options = new DbContextOptionsBuilder<GeoDbContext>().UseSqlite(connection, b => b.UseNetTopologySuite()).Options;

        using (var context = new GeoDbContext(options))
        {
            context.Database.EnsureCreated();
        }

        Console.ReadKey();
    }
}

public class GeoDbContext : DbContext
{
    public GeoDbContext()
    {

    }

    public GeoDbContext(DbContextOptions<GeoDbContext> options) : base(options)
    {

    }
}

}


### Further technical details
EF Core version: 2.2.1
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Operating system: Windows 10
IDE: Visual Studio 2017 15.9.5
Target framework: netcoreapp2.2
Complete List of nuget packages used to reproduce the bug:



```

closed-question customer-reported

Most helpful comment

I added the following line after
connection.Open();
connection.EnableExtensions();

and it worked

All 2 comments

I was just about to create this issue when it popped up in the suggested issues box. Thanks!

I added the following line after
connection.Open();
connection.EnableExtensions();

and it worked

Was this page helpful?
0 / 5 - 0 ratings