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

  • SEARCH
  • Home
  • 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 6834549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:07:30+00:00 2026-05-26T23:07:30+00:00

I have C#.Net winform application having SQL Server Database in SQLExpress with Windows Authentication.

  • 0

I have C#.Net winform application having SQL Server Database in SQLExpress with Windows Authentication.
There is a Option related to Backup and restore batabase. In DBbackup i have provided user to select folder and database will be copy to that folder.
for restore database i have written following line:

System.IO.File.Copy(filePath, Application.StartupPath + "\\dbSTK.mdf",true);

it throws an exception saying dbSTK is already in use. How can i overwrite file that is already in use?

  • 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-26T23:07:31+00:00Added an answer on May 26, 2026 at 11:07 pm

    A .mdf file is not a backup file, but the actual data file. You cannot simply copy a running database (or overwrite a running database.) Typically you would have to use sp_detach_db to get the file in state that you can copy/archive and sp_attach_db (or create database for attach) to restore the db.

    If you just made a copy of the running .mdf as a backup, then the odds are pretty good that you won’t be able to attach that file.

    While the above is the correct method to detach/attach a database, I would suggest actually performing a backup/restore. It doesn’t require taking the database offline and is generally a better approach to managing backups.

    How to attach a data file in SQL Server: http://msdn.microsoft.com/en-us/library/ms179877.aspx

    How to detach a database in SQL Server: http://msdn.microsoft.com/en-us/library/ms188031.aspx

    How to perform a backup on SQLEXpress: http://msdn.microsoft.com/en-us/ms186865.aspx

    How to restore a backup on SQLExpress: http://msdn.microsoft.com/en-us/ms186858

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

Sidebar

Related Questions

I have a Winform application built with C# and .Net 2.0. I have a
I have a .NET 4 WinForm application. I have bound a DataGrid to a
i have a very simple winform application in vb.net and i was wondering how
I have a .Net Compact Framework WinForm application , I want to catch Application
I have inherited a frankenstein VB6 Converted to VB.NET winform application. This application has
I have a .NET winform application that writes an XML data file, but I
I have a .NET WinForm application. I want when my application run, it will
I have an .NET 4 WinForm application. I have a button on the main
I have a C#.NET Winform Application, using which, printing of bills etc. would be
I have following code for 3 DataGridView Controls in my VB.NET winform application. How

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.