Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

database backup and restore in sql server 2005 Expand / Collapse
Author
Message
Posted Wednesday, July 22, 2009 5:08 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, October 03, 2009 2:56 AM
Points: 11, Visits: 25
Need help in taking database backup and restore using java......

Database: SQLServer 2005

I have done it this way.....

SQL Backup Query="BACKUP DATABASE mydatabase TO disk=?";

while executing, iam getting the following error ....

Cannot perform a backup or restore operation within a transaction.

Also let me know, how to make a forced database backup?

Post #757297
Posted Wednesday, July 22, 2009 5:28 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 6:27 AM
Points: 6,997, Visits: 8,411
Which driver are you using ?

Are you (or the driver by default) using implicit transactions ?

A backup/restore operation cannot be incapsulated with a transaction.
If a restore fails, the db is left in its failed state (restoring) !


Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #757306
Posted Wednesday, July 22, 2009 5:52 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:05 AM
Points: 14,802, Visits: 27,276
What do you mean by a "forced" database backup?



----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #757316
Posted Wednesday, July 22, 2009 6:31 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, October 03, 2009 2:56 AM
Points: 11, Visits: 25
thanks for the reply.......

Iam using type 4 driver (sqljdbc) .......

If a query has to be executed, it has to be in transaction......

Or else is there any other way?

What do you mean by a "forced" database backup?

Sometimes, while executing the query i have encountered the following error

"some active connections.........."
So before going ahead, i need to close the active connections and then proceed further.......So, in such cases is it possible to make forced backup and restore...

Note: forced in the sense, complete the database operations irrespective of active connections
Post #757357
Posted Wednesday, July 22, 2009 6:59 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 6:27 AM
Points: 6,997, Visits: 8,411
abhishek.c1984 (7/22/2009)
... "some active connections.........."
So before going ahead, i need to close the active connections and then proceed further.......So, in such cases is it possible to make forced backup and restore...

Note: forced in the sense, complete the database operations irrespective of active connections


Probably it refers to open connections to the target database of your restore operation.

If you want to restore with interrupting all connections,
just start your restore statement by adding
alter database yourdb set offline with rollback immediate ;
restore database ...



Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #757387
Posted Wednesday, July 22, 2009 7:24 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:05 AM
Points: 14,802, Visits: 27,276
Ah, right. ALZDBA answered it. You're not forcing the backup, you're forcing the restore, but not even that really, you're just kicking all the users off the database.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #757418
Posted Thursday, July 23, 2009 12:11 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, October 03, 2009 2:56 AM
Points: 11, Visits: 25
thanks for the reply,

I have just executed the query in SQL Server 2005, it worked fine...but the database connection was broken

-------
Nonqualified transactions are being rolled back. Estimated rollback completion: 100%.
Failed to restart the current database. The current database is switched to master.
RESTORE DATABASE successfully processed 561 pages in 0.350 seconds (13.130 MB/sec).

---------------------

But it failed to start the current database...

Error:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset by peer: socket write error


Note: How can i use this query in the application?
It is giving the following error

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: ALTER DATABASE statement not allowed within multi-statement transaction.
Post #757985
Posted Thursday, July 23, 2009 1:31 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 6:27 AM
Points: 6,997, Visits: 8,411
abhishek.c1984 (7/23/2009)
thanks for the reply,

I have just executed the query in SQL Server 2005, it worked fine...but the database connection was broken

-------
Nonqualified transactions are being rolled back. Estimated rollback completion: 100%.
Failed to restart the current database. The current database is switched to master.
RESTORE DATABASE successfully processed 561 pages in 0.350 seconds (13.130 MB/sec).

---------------------

But it failed to start the current database...

Error:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset by peer: socket write error


Note: How can i use this query in the application?
It is giving the following error

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: ALTER DATABASE statement not allowed within multi-statement transaction.


Don't use a transaction to perform backup or restore operations !!
( it does not have a transaction scope - there is no rollback feature for backup / restore !)

Do not connect to the database you are trying to restore !

Connect to master or tempdb to perform your database restore operation.



Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #758008
Posted Thursday, July 23, 2009 3:14 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, October 03, 2009 2:56 AM
Points: 11, Visits: 25
thanks for the reply.....

Can you please let me know how can i connect to master or tempdb to perform database restore operation.

Tell me how to perform this operation from the java application, without being connected to database
Post #758048
Posted Thursday, July 23, 2009 3:52 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 6:27 AM
Points: 6,997, Visits: 8,411
BP is always to specify the database name you want to connect to (don't rely on the logins default database ! A sql instance can host multiple databases !)

Check out BOL for the jdbc driver: http://msdn.microsoft.com/en-us/library/ms378988%28SQL.90%29.aspx

IMO you should provide as many info as you can in your connection !
This will help with problem solving, monitoring, ...


e.g.
// Get connection
DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
String url="jdbc:microsoft:sqlserver://yourip;DatabaseName="yourdb";
Connection conn=DriverManager.getConnection(url,"username","password");


Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #758058
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse