Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6111213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:36:17+00:00 2026-05-23T14:36:17+00:00

I have written a program in C# to use SQL 2008. I want to

  • 0

I have written a program in C# to use SQL 2008.

I want to backup the database and restore it. My code for backup works correctly but restore doesn’t work and the database becomes single user.

Get the following error :

The tail of the log for the database
“doctor” has not been backed up. Use
BACKUP LOG WITH NORECOVERY to backup
the log if it contains work you do not
want to lose. Use the WITH REPLACE or
WITH STOPAT clause of the RESTORE
statement to just overwrite the
contents of the log. RESTORE DATABASE
is terminating abnormally.
Nonqualified transactions are being
rolled back. Estimated rollback

My code:

private void Backup(string strFileName)
{
    try
    {
        string command = @"BACKUP DATABASE doctor TO DISK='"+ strFileName+"'";
        SqlCommand oCommand = null;
        SqlConnection oConnection = null;
        oConnection = new SqlConnection("Data Source=.;Initial Catalog=doctor;Integrated Security=True");
        if (oConnection.State != ConnectionState.Open)
        oConnection.Open();
        oCommand = new SqlCommand(command, oConnection);
        oCommand.ExecuteNonQuery();


    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}   

private void Restore(string strFileName)
{
    try
    {
        string command = "ALTER DATABASE doctor SET SINGLE_USER with ROLLBACK IMMEDIATE " + "use master " + " RESTORE DATABASE doctor FROM DISK='" + strFileName + "'";
        SqlCommand oCommand = null;
        SqlConnection oConnection = null;
        oConnection = new SqlConnection("Data Source=.;Initial Catalog=doctor;Integrated Security=True");
        if (oConnection.State == ConnectionState.Closed)
        {
            oConnection.Open();
            oCommand = new SqlCommand(command, oConnection);
            oCommand.ExecuteNonQuery();               
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:36:18+00:00Added an answer on May 23, 2026 at 2:36 pm

    I think if you concat

    ” WITH REPLACE “

    with your restore string it would work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a C# program in Visual Studio 2010 . I use database
I have a Python CLI program, with SQL database models and want to add
I have written a program which uses a SQL exception class and then use
I have written a program that uses qhttp to get a webpage. This works
Visual Studio C++ 2008 / GCC 4.4.2 I have written a program to run
I have written a java program that is actually works as a gui to
I have a Perl program that I've written that parses SQL-like statements and creates
I have a database process written in PL/SQL that i would like to test
I have written a program which works on huge set of data. My CPU
I have written a program in visual basic and want it to display the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.