Embedded Resource表示数据库已嵌入到您的dll中。Copy to output directory设置在这种情况下不适用,它用于Build Action: Content
嵌入数据库后,您基本上必须在首次使用时将其取消嵌入。为此,将其从Assembly中读取并将其存储到文件中。
class EmbeddedResourceTest { public static void Test() { string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Test.db"); using(var resourceStream = typeof(EmbeddedResourceTest).Assembly.GetManifestResourceStream("Test.db")) { using(var fileStream = File.OpenWrite(path)) { CopyStream(resourceStream, fileStream); } } // now access database using 'path' } public static void CopyStream(Stream inputStream, Stream outputStream) { CopyStream(inputStream, outputStream, 4096); } public static void CopyStream(Stream inputStream, Stream outputStream, int bufferLength) { var buffer = new byte[bufferLength]; int bytesRead; while ((bytesRead = inputStream.Read(buffer, 0, bufferLength)) > 0) { outputStream.Write(buffer, 0, bytesRead); } } }
标签:sqlite,outputStream,CopyStream,Stream,嵌入式,static,var,inputStream,winform From: https://www.cnblogs.com/qingjiawen/p/17407064.html