Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


database backup and restore in sql server 2005


database backup and restore in sql server 2005

Author
Message
abhishek.c1984
abhishek.c1984
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 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?
ALZDBA
ALZDBA
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8153 Visits: 8849
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


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- 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 :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19941 Visits: 32371
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 Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
abhishek.c1984
abhishek.c1984
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 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
ALZDBA
ALZDBA
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8153 Visits: 8849
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


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- 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 :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19941 Visits: 32371
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 Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
abhishek.c1984
abhishek.c1984
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 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.
ALZDBA
ALZDBA
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8153 Visits: 8849
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


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- 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 :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
abhishek.c1984
abhishek.c1984
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 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
ALZDBA
ALZDBA
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8153 Visits: 8849
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


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- 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 :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search