找不到 SQLite 方法:'IntPtr SQLitePCL.sqlite3.get_ptr()'

我正在尝试在 .Net Standard 2.0 项目中使用 c# 和 microsoft.data.sqlite 实现 SQLite 数据库。


当我调用 connection.Open() 时,我不断收到错误“找不到方法:'IntPtr SQLitePCL.sqlite3.get_ptr()'”


我已经下载了以下 Nuget 包:


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

我执行如下:


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();

            }

        }

一切都建立起来了。在运行时,当执行以下块时,我得到:“未找到方法:'IntPtr SQLitePCL.sqlite3.get_ptr()'”on Connection.Open();


慕慕森
浏览 81回答 1
1回答

千万里不及你

将 Microsoft.Data.Sqlite 和 Microsoft.Data.Sqlite.Core 包更新到 Entity Framework Core 版本 3.0.0 将解决该问题。这是我的 package.config 参考:<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>
打开App,查看更多内容
随时随地看视频慕课网APP