473,749 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem whille restoring the database

8 New Member
I design one application for backup and restore mechanism . When I press on the backup button it will successfully creates the backup file on the selected path. But when I want to restore the same database then that time it showing me an error "RESTORE cannot process database 'email_client' because it is in use bye this session. It is recommended that the master database be used when performing this operation.RESTO RE DATABASE is terminating abnormally"

so please provide coding for it
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10.  
  11. namespace Email_Client
  12. {
  13.     public partial class Backup : Form
  14.     {
  15.  
  16.         private SqlCommand cmd;
  17.         string sql = "";
  18.         public Backup()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void button2_Click(object sender, EventArgs e)
  24.         {
  25.             SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True");
  26.             con.Open();
  27.             try
  28.             {
  29.                 SqlCommand cmd = new SqlCommand("backup database email_client to disk ='" + textBox1.Text + "\\" + textBox2.Text + ".bak'", con);
  30.                 cmd.ExecuteNonQuery();
  31.                 MessageBox.Show("done");
  32.  
  33.  
  34.             }
  35.             catch (Exception ex)
  36.             {
  37.                 MessageBox.Show(ex.Message);
  38.             }
  39.         }
  40.  
  41.         private void button1_Click(object sender, EventArgs e)
  42.         {
  43.             FolderBrowserDialog dlg = new FolderBrowserDialog();
  44.             if (dlg.ShowDialog() == DialogResult.OK)
  45.             {
  46.                 textBox1.Text = dlg.SelectedPath;
  47.             }
  48.         }
  49.  
  50.         private void button4_Click(object sender, EventArgs e)
  51.         {
  52.             OpenFileDialog dlg = new OpenFileDialog();
  53.             dlg.Filter = "Backup files(*.bak)|*.bak|All Files(*.*)|*.*";
  54.             dlg.FilterIndex = 0;
  55.             if (dlg.ShowDialog() == DialogResult.OK)
  56.             {
  57.                 textBox3.Text = dlg.FileName;
  58.             }
  59.  
  60.         }
  61.  
  62.         private void button3_Click(object sender, EventArgs e)
  63.         {
  64.  
  65.             SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True");
  66.             con.Open();
  67.             try
  68.             {
  69.  
  70.                 sql = "alter database email_client set single_user with rollback immediate ;";
  71.                 sql += "RESTORE database email_client from disk='"+textBox3.Text+"'with replace;";
  72.                 cmd = new SqlCommand(sql, con);
  73.                 cmd.ExecuteNonQuery();
  74.                 con.Close();
  75.                 con.Dispose();
  76.                 MessageBox.Show("done");
  77.  
  78.             }
  79.             catch (Exception ex)
  80.             {
  81.                 MessageBox.Show(ex.Message);
  82.             }
  83.  
  84.         }
  85.  
  86.         private void Backup_Load(object sender, EventArgs e)
  87.         {
  88.  
  89.         }
  90.     }
  91. }
  92.  
Attached Images
File Type: jpg Screenshot (16).jpg (35.2 KB, 144 views)
Feb 22 '14 #1
0 1156

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1433
by: JW | last post by:
I have 2 backup files (using mysqldump.) The first one is for the whole database, backed up from Januaray to July 25. The second one is just for 2 tables of that database, backed up from June 29 to July 29. These 2 tables are updated continuously, and from July 25 to July 29, there is no new record in the rest of the tables. The data in both files contains foreign characters, and are encoded by UTF-8 character set. The problem is that now...
1
3252
by: Tom Loach | last post by:
I have the need to restore a database to a user's laptop on a daily basis. This has been no problem using Enterprise Manager. I found a stored procedure to run the restore and tried to call it from a visual basic program. While I can connect to the database, I get an error telling me "exclusive access could not be obtained because the database is in use". Does this mean the only way to run the restore is via Enterprise Manager? ...
1
6583
by: Yass | last post by:
Dear Newsgroup, I am using sql server 2000 over win 2000 server with service pack 4. I have been given a back up of a database (I have tried both from T-SQL and Enterprise Manager) T-SQL
6
1717
by: Rajesh Kumar Mallah | last post by:
Hi, I face the following problem in transferring data from pgsql 7.3.4 to pgsql 7.4 RC1 . I am piping the output of pg_dumpall from 7.3 to 7.4 running on different port. The problem is there is a gist index on txtidx type on a non-public schema and when search_path does not include public the index cannot be created.
0
1449
by: Wind Wood | last post by:
Hello £¡ I can dump data from old dababase(Postgresql 6.5.3), but new problem came out when I restore the data to postgresql 7.4. It went out during the COPY command, if I do it in such command lines: 1. pg_dump news -f pgsql-database-news.sql #in old system with postgresql 6.5.3 2. su - postgres #in new system with postgresql 7.4 3. createdb -T template0 news 4. psql news < pgsql-database-news.sql ------
3
2705
by: mike | last post by:
I have just upgraded froom Fedora test1 to test2 which has upgraded postgres version from 7.4.2 to 7.4.5 (frrom rpm -q) I have used pg_dumpall to dump my database, the restore appeared to go OK, except there is no data in two of my tables (only these two) output from \d \d tb_invoice_header Table "public.tb_invoice_header" Column | Type
0
1375
by: mahesh123 | last post by:
Hi, I am new to use the crystal reports8.0. I am facing the problem regarding the database connection through the ADO Connection. Suppose my database name is "sample.pra"(due to some security reasons we will change the extension of the MS Access Database and there is a password for the opening the database). So that we cannot connect to the database. Please give the information regarding this problem as soon as possible...... Thanks &...
0
3701
by: DMT012 | last post by:
Hello. Occasionally on my production server when I run an automated script to restore a database from a backup it hangs and the database is put in restoring mode and just stays there, requiring me to delete the database and restore the backup manually and causing everything else to timeout (it's part of an update process that includes database and web files). The code is called from a VB.Net DLL against the Master database and is as...
1
1573
by: babu | last post by:
Hi all I am trying to take exchange server 2003 backup and restore programmatically. My backup function works fine. But i am in problem in restoring database. My HrESERestoreAddDatabase is not working well. The HrESERestoreAddDatabase is returning HRESULT -939587631. Will anyone give me any link related exchange server 2003 backup? Or can anyone give me sample code or link to sample code related to HrESERestoreAddDatabase() method?...
0
8997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9389
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.