Thanks for the input. I have written my own code to implement it. Please find the bellow steps. 1. Import the below Native methods
\[DllImport("System.Data.SQLite.dll")\]
public static extern int sqlite3\_backup\_init(IntPtr pTo, string toName, IntPtr pFrom, string fromName);
\[DllImport("System.Data.SQLite.dll")\]
public static extern int sqlite3\_backup\_step(int b, int n);
\[DllImport("System.Data.SQLite.dll")\]
public static extern int sqlite3\_backup\_finish(int backupObject);
\[DllImport("System.Data.SQLite.dll")\]
public static extern int sqlite3\_sleep(int interval);
\[DllImport("System.Data.SQLite.dll")\]
public static extern int sqlite3\_backup\_remaining(int remaining);
\[DllImport("System.Data.SQLite.dll")\]
public static extern int sqlite3\_backup\_pagecount(int pageCount);
2. Define the below constants
public const int SQLITE\_OK = 0;
public const int SQLITE\_BUSY = 5;
public const int SQLITE\_LOCKED = 6;
3. Above APIs required database as IntPtr. But we have only a connection class [System.Data.SQLite.SQLiteConnection]. So we need to find out database handle from the connection object. I don't know whether it is a right way or not, anyway implement an extension method as shown below
public static IntPtr GetConnectionHandle(this SQLiteConnection connection)
{
IntPtr returnPointer = IntPtr.Zero;
FieldInfo\[\] fields = typeof(SQLiteConnection).GetFields(
BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.DeclaredOnly);
object sqLiteBase = null;
object value = null;
//Checks the valid connection states
if (connection.State != System.Data.ConnectionState.Open &&
connection.State != System.Data.ConnectionState.Fetching &&
connection.State != System.Data.ConnectionState.Executing)
{
return returnPointer;
}
foreach (FieldInfo info in fields)
{
//Getting the object "internal SQLiteBase \_sql;" from the
//public class instance System.Data.SQLite.SQLiteConnection.
if (string.Compare(info.Name, "\_sql", true) == 0)
{
sqLiteBase = info.GetValue(connection);
break;