Click here to Skip to main content
15,997,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
code
DateTime d = DateTime.Now;
                string dd = d.Day + "," + d.Month;
                string dbname = textBox1.Text;
                OleDbConnection conn = new OleDbConnection();
                conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:/dipti/Data/ERPDB.accdb";
                conn.Open();
            //string str = "USE " + dbname + ";";
            string str1 = "backup database" + dbname + "to disk = 'E:\\database\\" + dbname + "_" + dd + ".bak";
            //OleDbCommand cmd1 = new OleDbCommand(str, conn);
            OleDbCommand cmd2 = new OleDbCommand(str1, conn);
            // cmd1.ExecuteNonQuery();
            cmd2.ExecuteNonQuery();
                MessageBox.Show("Successfully");
                conn.Close();


What I have tried:

please help
<pre>DateTime d = DateTime.Now;
                string dd = d.Day + "," + d.Month;
                string dbname = textBox1.Text;
                OleDbConnection conn = new OleDbConnection();
                conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:/dipti/Data/ERPDB.accdb";
                conn.Open();
            //string str = "USE " + dbname + ";";
            string str1 = "backup database" + dbname + "to disk = 'E:\\database\\" + dbname + "_" + dd + ".bak";
            //OleDbCommand cmd1 = new OleDbCommand(str, conn);
            OleDbCommand cmd2 = new OleDbCommand(str1, conn);
            // cmd1.ExecuteNonQuery();
            cmd2.ExecuteNonQuery();
                MessageBox.Show("Successfully");
                conn.Close();
Posted
Updated 1-Nov-19 8:27am

You missed the closing quote:
C#
string str1 = "backup database" + dbname + "to disk = 'E:\\database\\" + dbname + "_" + dd + ".bak";

                                                      ^
 
Share this answer
 
Comments
Richard Deeming 1-Nov-19 14:19pm    
I don't think that's going to help - the code is connecting to an Access database. :)
BACKUP DATABASE is a SQL Server command. You are connecting to an MS Access database.

To backup an Access database, you just need to copy the database file.
C#
string sourceFile = @"F:\dipti\Data\ERPDB.accdb";
string destinationFile = @"E:\database\" + dbname + "_" + dd + ".bak";
System.IO.File.Copy(sourceFile, destinationFile, overwrite: true);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900