1

我想在 sqlite 数据库中存储大文件(超过 100mb)。我注意到,它的性能不好。我必须将文件存储在本地文件夹中,还是必须重写我的代码?

       Shared Sub BlobToFile(ByVal Blob As Byte(), ByVal file As String)
        Dim MyData() As Byte = Blob
        Dim K As Long
        K = UBound(MyData)
        Dim fs As New FileStream _
         (file, FileMode.Create, _
          FileAccess.Write)
        fs.Write(MyData, 0, K)
        fs.Close()
        MyData = Nothing
        K = Nothing
    End Sub
    Shared Function FileToBlob(ByVal Filepath As String) As Byte()
        Dim fs As New FileStream _
     (Filepath, FileMode.Open, _
      FileAccess.Read)
        Dim MyData(fs.Length) As Byte
        fs.Read(MyData, 0, fs.Length)
        fs.Close()
        Return MyData
    End Function
'Then I Do this:
Dim x As New Sqliteparameter With {.Name ="@file", .value=Filetoblob("C:\Testfile.zip"), .DbType.Binary}
Dim y As New SqliteCommand With {.Commandtext = "INSERT INTO FILES(File) Values(@file);"}
y.Parameters.add(x)
y.Executenonquery()

谢谢

4

1 回答 1

3

通常最好的做法是不要将大文件存储在数据库中,除非有对它的支持,例如 mssql 服务器。我建议只查看将文件的位置存储在数据库中并将文件存储在某种文件系统中。

于 2012-04-22T14:18:22.637 回答