我正在使用 local database 来存储我的数据。我的代码基于教程:How to create a basic local database app for Windows Phone 一切正常,但我不得不向我的数据库添加更多数据,现在当我尝试这样做时,我得到信息“你的手机存储空间不足”。是不是我的数据库太大了?

这是我创建数据库的方式:

using (TablesDataContext db = new TablesDataContext(TablesDataContext.DBConnectionString))
{
    if (db.DatabaseExists() == false)
    {
       //Create the database
        db.CreateDatabase();
    }
}

还有我的 DataContext :
public class TablesDataContext : DataContext
    {
        // Specify the connection string as a static, used in main page and app.xaml.
        public static string DBConnectionString = "Data Source=isostore:/Customers.sdf";

        // Pass the connection string to the base class.
        public TablesDataContext(string connectionString)
            : base(connectionString)
        { }

        // Specify a single table for the to-do items.
        public Table<CustomerItem> CustomersTable;
        public Table<CategorieItem> CategoriesTable;
        public Table<ProductItem> ProductsTable;
        public Table<CustomerPricesItem> CustomerPricesTable;
    }

最佳答案

您确定您的手机有足够的可用存储空间吗?

如果您的手机有足够的可用空间,您可以尝试在连接字符串中添加 Max Database Size 参数。默认情况下,当您第一次创建数据库时,大小设置为 32Mb。包括 最大数据库大小 您可以指定所需的大小,最大值为 512Mb:

"Data Source='isostore:/Db.sdf'; Max Database Size = 256;"

这样,第一次使用上述连接字符串创建数据库时,最大大小设置为 256Mb。

另外,我知道这是另一个问题,但是如果您的写入是大量数据,您可能希望将 最大缓冲区大小 参数添加到连接字符串中,最大值为 5120 (5Mb),它表示在继续写入磁盘之前存储在内存中的数据......它可以加速您的写入:
"Data Source='isostore:/Db.sdf'; Max Database Size = 256; Max Buffer Size = 3072;"

如果您的数据比这更大,也许您需要将其拆分为不同的文件或使用另一个数据库作为 SQLite。

您在数据库中存储了哪些数据?图片?只有文本...二进制文件...也许有更好的方法来优化数据库大小,如果您将图像存储在 db 字段中,则最好将图像存储在隔离存储中,并将路径存储在 db 中。

希望这有帮助!

关于c# - 使用本地数据库时存储空间不足错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14625791/

10-13 07:34
查看更多