Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用SQLite.Net设置多个pragma?_C#_Sqlite_Uwp_Windows 10 - Fatal编程技术网

C# 如何使用SQLite.Net设置多个pragma?

C# 如何使用SQLite.Net设置多个pragma?,c#,sqlite,uwp,windows-10,C#,Sqlite,Uwp,Windows 10,打开与数据库的连接后,我可以设置一个PRAGMA,但第二个PRAGMA总是失败。如何使用SQLite.Net-pcl3.1.1设置这两个PRAGMA?这是针对通用Windows平台应用程序的 public static SQLiteConnection Open() { if (db == null) { var dbPath = Path.Combine(ApplicationData.Current.LocalFolde

打开与数据库的连接后,我可以设置一个PRAGMA,但第二个PRAGMA总是失败。如何使用SQLite.Net-pcl3.1.1设置这两个PRAGMA?这是针对通用Windows平台应用程序的

    public static SQLiteConnection Open()
    {
        if (db == null)
        {
            var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, DatabaseFileName);
            db = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath);
            db.Execute("PRAGMA foreign_keys = ON");
            db.Execute("PRAGMA journal_mode = WAL");
        }
        return db;
    }
在第二个execute语句之后,我立即从SQLite获得一个“Row”异常

请求的堆栈跟踪:

  • 在SQLite.Net.SQLiteCommand.ExecuteNonQuery()中
  • 在SQLite.Net.SQLiteConnection.Execute(字符串查询,对象[]args)
  • 在SceneLocker.Models.DBConnection.Open()中
编辑:添加捕获异常的屏幕截图:

在第二个execute语句之后,我立即从SQLite获得一个“Row”异常

“行”异常意味着语句返回一行结果,
db.Execute

作为解决方法,您可以使用
db.CreateCommand
执行该语句:

var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "MyDB.db");
db = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath);
db.Execute("PRAGMA journal_mode=DELETE");
var cmd=db.CreateCommand("PRAGMA journal_mode=WAL",new object[] { });//use db.CreateCommand
var result=cmd.ExecuteQuery<object>();//execute the command
var dbPath=Path.Combine(ApplicationData.Current.LocalFolder.Path,“MyDB.db”);
db=新的SQLiteConnection(新的SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(),dbPath);
db.Execute(“PRAGMA journal_mode=DELETE”);
var cmd=db.CreateCommand(“PRAGMA journal_mode=WAL”,新对象[]{})//使用db.CreateCommand
var result=cmd.ExecuteQuery()//执行命令

感谢您对实际的错误消息保密。异常内容只是说“行”。您是在暗示您得到一个只有“行”一词的空屏幕吗?编辑是一种改进,但一般来说,尽量避免使用图片。不能用谷歌搜索其中的文本。请添加stacktrace的全文。非常感谢!我将此标记为答案,因为它使我意识到第二个Execute语句正在返回一个结果。我用ExecuteScalar替换了第二个Execute,它就像一个符咒。