I am trying to implement a SQLite database using c# and microsoft.data.sqlite in a .Net Standard 2.0 Project.
I keep getting the error "Method not found: 'IntPtr SQLitePCL.sqlite3.get_ptr()'" when I call connection.Open()
I have downloaded the following Nuget Packages:
<ItemGroup>
<PackageReference Include="Microsoft.Data.SQLite" Version="2.2.6" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.0.0" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.0.0" />
<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="2.0.0" />
<PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.0.0" />
<PackageReference Include="SQLitePCLRaw.provider.e_sqlite3.netstandard11" Version="1.1.14" />
</ItemGroup>
I am executing it as follows:
private static SqliteConnection _sqlConnection = new SqliteConnection(@"Data Source = myPath");
public static Int64 InsertTransaction(string stringToInsert)
{
SQLitePCL.Batteries_V2.Init();
StringBuilder sqlToExecute = new StringBuilder();
sqlToExecute.Append("INSERT INTO table");
sqlToExecute.Append("(columnName) ");
sqlToExecute.Append("VALUES(' " + stringToInsert+ "')");
using (SqliteConnection connection = _sqlConnection)
{
connection.Open();
SqliteTransaction transaction = connection.BeginTransaction();
SqliteCommand sqlCommand = new SqliteCommand(sqlToExecute.ToString(), connection, transaction);
sqlCommand.ExecuteNonQuery();
}
}
Everything builds. At runtime, when the following block executes, I get: "Method not found: 'IntPtr SQLitePCL.sqlite3.get_ptr()'"on Connection.Open();
Update of Microsoft.Data.Sqlite and Microsoft.Data.Sqlite.Core packages to Entity Framework Core version 3.0.0 will solve the issue. See my similar question asked on Github. And here are my package.config references:
<packages>
<package id="Microsoft.Data.Sqlite" version="3.0.0-preview9.19423.6" targetFramework="net461" />
<package id="Microsoft.Data.Sqlite.Core" version="3.0.0-preview9.19423.6" targetFramework="net461" />
<package id="SQLitePCLRaw.bundle_e_sqlite3" version="2.0.2-pre20190904113843" targetFramework="net461" />
<package id="SQLitePCLRaw.bundle_green" version="2.0.2-pre20190904113843" targetFramework="net461" />
<package id="SQLitePCLRaw.core" version="2.0.2-pre20190904113843" targetFramework="net461" />
<package id="SQLitePCLRaw.lib.e_sqlite3" version="2.0.2-pre20190904113843" targetFramework="net461" />
<package id="SQLitePCLRaw.provider.dynamic_cdecl" version="2.0.2-pre20190904113843" targetFramework="net461" />
<package id="System.Buffers" version="4.5.0" targetFramework="net462" />
<package id="System.Memory" version="4.5.3" targetFramework="net462" />
<package id="System.Numerics.Vectors" version="4.6.0-preview5.19224.8" targetFramework="net461" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0-preview9.19421.4" targetFramework="net461" />
</packages>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With