deploying winform application with embedded sqlite
Embedded Resource
means the database gets embedded in your dll. The Copy to output directory
setting doesn't apply in this case, that's used for Build Action: Content
.
With the database embedded, you basically have to un-embed it on first use. To do this read it out of the Assembly and store it to a file.
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); } }}