tags:

views:

381

answers:

3

Hello friends,

I want to take a backup of my Access database Pragmatically. And After taking all data in backup i want to delete data from source database. ( So that it will not take much time while querying and filtering through application.)

The source database name is Data.mdb The destination database name is Backup.mdb Both are protected by same password.

For these purpose i am writing a query in C# like this.

string conString = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=Backup.mdb;Jet    
                   OLEDB:Database Password=12345";
OleDbConnection dbconn = new OleDbConnection();
OleDbDataAdapter dAdapter = new OleDbDataAdapter();
OleDbCommand dbcommand = new OleDbCommand();

try
{
   if (dbconn.State == ConnectionState.Closed)
      dbconn.Open();

 string selQuery = "INSERT INTO [Bill_Master] SELECT * FROM [MS Access;DATABASE="+     
                   "\\Data.mdb" + "; Jet OLEDB:Database Password=12345;].[Bill_Master]";

 dbcommand.CommandText = selQuery;
 dbcommand.CommandType = CommandType.Text;
 dbcommand.Connection = dbconn;
 int result = dbcommand.ExecuteNonQuery();
 }
 catch(Exception ex)   {}

Everything goes fine if i try with without password database file. I think error in passing password on query statement. I am trying to execute through access query but it is saying "Invalid argument". Please is there any other programing logic for doing that. Thanks

prashant YuvaDeveloper

+3  A: 

Are Data.mdb and Backup.mdb identically in strcuture? If so, I wouldn't bother copying data via SQL but just copy the whole file.

Maximilian Mayerl
ya its identical but As i said i delete all data from source file.In future again i will fill new data on my source file, And again want a backup with just copy and paste then i loose my data which is residing in my backup.mdb file.thanks
prashant
Then copy the original to the backup file name, then clear all the data in the original. Is there some reason that won't work? It's certainly what Maximilian suggested.
David-W-Fenton
+1  A: 

You can copy and rename Data.mdb, and then truncate all the tables in Data.mdb. Far easier than trying to copy a table at a time..

slashmais
Actually some data should persist on my current database.Thats why i just move some of table data to backup.
prashant
Data.Mdb Backup.Mdb==data1==data2===data3 --------->Move ===data1 ===data2 ===data3--------------------------------------------Add new data again on Data.mdb===Data4===Data5 ------>Move ===data1 ===data2 ===data3 ===data4 ====data5like this.it should add on my db
prashant
+1  A: 

Don't delete data. This becomes a lot mroe difficult in the future to do analysis or inquiries. If it's taking a long time then review indexing or upszing to SQL Server. The Express edition is free and can handle databases up to 4 Gb.

Tony Toews
It's Ok. I wont delete data. But how i insert the values from another table.What should be my querystring selQuery = "INSERT INTO [Bill_Master] SELECT * FROM [MS Access;DATABASE="+ "\\Data.mdb" + "; Jet OLEDB:Database Password=12345;].[Bill_Master]";
prashant
strSQL = "INSERT INTO ServiceRecordInvoices " "where strDatabasePathandName is the database path and name. Hmm, there's a password? I don't know if the above will work then.
Tony Toews