473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem in copying SQLite file in C# code

I have a little Windows application written in C# with a SQLite back-
end. I'm using the System.Data.SQLite provider.

One of the features the application provides is a database back-up,
which just basically copies the S3DB file to a specified location. See
the code below:

//------------------------------------------------
System.IO.File.Copy(srcPath, destPath, true);
//------------------------------------------------

The file is copied without any problems, but when the application
attempts to access the original S3DB file again, the following
exception is thrown:

--------------------------------------------------
System.Data.SQLite.SQLiteException was unhandled
Message="Unable to open the database file"
Source="System.Data.SQLite"
ErrorCode=-2147467259
StackTrace:
....etc...
--------------------------------------------------

If I shut the application down and then start it up again, I can
access the database again with no problems.

Suspicious of what the File.Copy() method might be doing behind the
scenes, I tried using the following approach instead to hopefully
ensure that the files were being released:

//------------------------------------------------
using (FileStream fsSrc = new FileStream(srcPath, FileMode.Open))
{
//Get the source length once so we don't have to keep retrieving it
later
int srcLen = (int)fsSrc.Length;

//Create the destination file (this will overwrite the destination
file if it already exists)
using (FileStream fsDest = File.Create(destPath, srcLen))
{
//Buffer the contents of the source file
Byte[] buffer = new Byte[srcLen];
fsSrc.Read(buffer, 0, srcLen);

//Write buffered contents to the new file
fsDest.Write(buffer, 0, srcLen);
}
}
//------------------------------------------------

Unfortunately, the same problem occurs. I even tried executing the
code in its own thread, but with the same results.

Any ideas why this is happening and how to fix it?

Thank you.

Oct 26 '07 #1
0 1592

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Zoo Keeper | last post by:
For some reason, the Python preprocessing balks on the "\" line continuation character. Any ideas/thoughts? Is it just that my version of gcc is not supported? I don't "need" numeric in my...
12
by: John Salerno | last post by:
I've been looking around and reading, and I have a few more questions about SQLite in particular, as it relates to Python. 1. What is the current module to use for sqlite? sqlite3? or is that not...
4
by: Jim Carlock | last post by:
I added the following lines to PHP.INI. extension=php_pdo.dll extension=php_pdo_sqlite.dll extension=php_sqlite.dll specifically in that order. I noticed the extensions getting loaded are...
3
by: ricardo.turpino | last post by:
Hi, I've installed Mac Python 2.5. I'm running Mac OS X 10.4.10 on a Macbook 1.83GHz. I though that the python sqlite library was installed by default as part of Mac Python 2.5, however, I...
0
by: swathi123 | last post by:
hi all here im trying to create .csv file. my code is public class CSVFile { public static void main(String args) { String record=null; try {
4
by: mahdaeng | last post by:
I have a little Windows application written in C# with a SQLite back- end. I'm using the System.Data.SQLite provider. One of the features the application provides is a database back-up, which...
2
by: Joe Goldthwaite | last post by:
I'm confused. (Not a new experience). I've got a web application running under Zope. I use the Wing IDE for testing and debugging. When trying to recreate problems that come up on the web, I...
0
by: Guilherme Polo | last post by:
On Tue, Jul 1, 2008 at 9:51 PM, Joe Goldthwaite <joe@goldthwaites.comwrote: You need sqlite itself (www.sqlite.org) and bindings, pysqlite 2 (http://oss.itsystementwicklung.de/trac/pysqlite/) or...
0
by: Joe Goldthwaite | last post by:
Thanks Guilherme. That helped. I guess I was thinking that pysqlite would automatically come with some version of sqlite. The fact that it doesn't is what was causing me to get the strange...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.