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 7491589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:04:58+00:00 2026-05-29T16:04:58+00:00

I have a database (mdf file) which I’m approaching with the Entity Framework. Is

  • 0

I have a database (mdf file) which I’m approaching with the Entity Framework. Is it possible to make a backup of the MDF file.
I tried already but SMO but the problem is because I’m using a mdf file the database name is empty. I’ve read that it’s autogenerated.

Piece of my backup code:

        String destinationPath = "C:\\";
        Backup sqlBackup = new Backup();

        sqlBackup.Action = BackupActionType.Database;
        sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString();
        sqlBackup.BackupSetName = "Archive";
        
        BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
        ServerConnection connection = new ServerConnection(".\\SQLEXPRESS");
        Server sqlServer = new Server(connection);
        StringCollection sc = new StringCollection();
        sc.Add(Environment.CurrentDirectory + "\\db\\Xmain.mdf"); //Bin directory
        sc.Add(Environment.CurrentDirectory + "\\db\\Xmain_log.ldf");
        sqlServer.AttachDatabase("Xmain", sc);
        Database db = sqlServer.Databases["Xmain"];
        sqlBackup.Initialize = true;
        sqlBackup.Checksum = true;
        sqlBackup.ContinueAfterError = true;
        
        sqlBackup.Devices.Add(deviceItem);
        sqlBackup.Incremental = false;

        sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
        sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;

        sqlBackup.FormatMedia = false;

        sqlBackup.SqlBackup(sqlServer);
  • 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-29T16:05:00+00:00Added an answer on May 29, 2026 at 4:05 pm

    I am missing something here and need more context, but I will rant on for a second and see if anything is helpful.

    Do you mean actually back up the file, not the data? If so, the easy answer is no. The problem is SQL Server will lock the file when it is attached to the database server (SQL Express in this case). You can detatch and copy and then attach, but the application will be down during that time. This can also be done manually.

    If you want to backup the data, I would consider scheduling it within SQL Server rather than programmatic, unless you cannot do it that way. Backup is more of a maintenance function than a part of the program.

    As for your database name being empty, that is impossible. In fact, it looks like you are trying to set up a database called XMain.

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

Sidebar

Related Questions

I have a database file in my C:/ directory (which I have also tried
I am using SQL Server 2008 and I have a database file (mydata.mdf) in
I have a WPF app with a local .MDF file on which I created
I have a database backup for which SQL Server Management Studio says that it
I have an .mdf file which I'm trying to add a record to, using
I have an error below adding an .mdf file (SQL Server Database) in a
I have been following some MVC tutorials that connect to a sql mdf database
I'm working on an ASP.NET MVC site which will have a database. While I'm
With a DataContext and a blank file-based database that already exists , is it
I have a project running on the tablet device which has .sdf file as

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.