Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 30th, 2006, 12:31 PM
Friend of Wrox
Join Date: Dec 2006
Location: , , .
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default back up sql data base

i want to back up my data and save it to my hard disk and restore it again by C#
please help me

best regards
kiani mehdi
  #2 (permalink)  
Old February 9th, 2007, 03:35 PM
Authorized User
Join Date: Oct 2003
Location: São Paulo, SP, Brazil.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to evandro.paula


You can create a command and execute the "BACKUP DATABASE". Take a look at the following sample:

            System.Data.SqlClient.SqlConnection connection = null;

                connection = new System.Data.SqlClient.SqlConnection();
                connection.ConnectionString = "Server=<server>;Initial Catalog=<db>;Integrated Security=SSPI; User Id=<user>;Password=<password>";

                System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
                command.CommandText = @"BACKUP DATABASE <db> TO DISK='C:\filename.bak'";
                command.Connection = connection;
            catch (System.Exception ex)
                if ((connection != null) && (connection.State != System.Data.ConnectionState.Closed))

  #3 (permalink)  
Old February 10th, 2007, 01:54 PM
Friend of Wrox
Join Date: Dec 2006
Location: , , .
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts

thank's so much for your usefull help

can you tell me how i can restore it from c#.net ?

bet regards
  #4 (permalink)  
Old February 11th, 2007, 10:49 AM
Friend of Wrox
Join Date: Dec 2006
Location: , , .
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts

thank you
and about restoring database i can restor database in fllowing steps
1)i set the data base to single_user then
2)i restor database with restore database SP
3)and finally i set database to multiple user

but in this way i have to write Application.Exitthread() at the end of step 3 becaus my app began hang up

what is the problem?
is there a better way for restoring database?

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data base Format virus220 ASP.NET 2.0 Professional 0 August 10th, 2007 09:37 AM
Data base connectivity watashi C# 2005 8 July 18th, 2007 08:05 PM
Transfering data from csv file to data base g_vamsi_krish ASP.NET 1.0 and 1.1 Professional 2 May 16th, 2006 11:58 PM
Data Base Connection ashraf Javascript 4 November 27th, 2004 06:56 AM

All times are GMT -4. The time now is 11:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.