How to perform backup and restore operations for SQL Server 2005 RRS feed

  • Question

  • Iam using JDBC to backup and Restore SQLServer 2005 database

    I have tried it this way, but iam getting the following exception while taking backup
    Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot perform a backup or restore operation within a transaction.

    public void backupDatabase()
            try {

                Connection con=DriverManager.getConnection(dburl, user, password);

                String backupQuery="BACKUP DATABASE dbname to disk=?";
                PreparedStatement stmt=con.prepareStatement(backupQuery);

                String path="C:\\database.bak";
                stmt.setString(1, path);


            } catch (Exception e) {


    For Restore:
    String restoreQuery="RESTORE DATABASE dbname  from disk=?";          

    Exception:com.microsoft.sqlserver.jdbc.SQLServerException: RESTORE cannot process database 'jiffy' because it is in use by this session. It is recommended that the master database be used when performing this operation.

    need help urgently......is there any other way of doing this
    Saturday, May 30, 2009 7:51 AM

All replies

  •   Hi,

    1.   do you have the right to execute the back up operation?
    2. the back up file path is in c partition,="C:\\database.bak";are you sure you can write to C partition?
        try to check them and test again.~
    you have a dream,you gonna protect it! http://www.cnblogs.com/frank_xl
    Wednesday, June 3, 2009 10:30 AM