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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:08:05+00:00 2026-05-25T01:08:05+00:00

I have a PC.sdf file that I work with. I close the connection and

  • 0

I have a PC.sdf file that I work with. I close the connection and I need to delete it.

I open the connection like this:

bool OpenConn()
{
  try
  {
     Conn = new SqlCeConnection(String.Format(@"Data Source={0}\{1}", PathI, "PC.SDF"));
     Conn.Open();
     return true;
   }
   catch 
   {
      //MessageBox.Show(err.Message, "Connetion error");
      return false;
   }
}

I close it like this:

Conn.Close();
Conn.Dispose();

I try to delete it like this:

if (File.Exists(@"\myPath\PC.sdf"))
    File.Delete(@"\myPath\PC.sdf");

But I get this error: file in use by another process. What could be the cause of this error, and how can I fix it?

  • 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-25T01:08:06+00:00Added an answer on May 25, 2026 at 1:08 am

    You could try and force garbage collection by running

    GC.Collect();
    

    Do this after you have Closed and Disposed of the DB object.

    This will of course only work if that is the only reference to that database file.

    Edit: Answer to comment about that you shouldn’t use GC.Collect to “fix” other issues.

    I don’t think this is because of another issue. The garbage collector runs at an indeterminate time chosen by the runtime. This means that you can’t rely on your object being disposed of between the followings lines.

    Conn.Dispose();
    //Nothing says GC will run exactly now
    File.Delete(@"C:\Some-file-used-by-Conn.db");
    

    Your options are to force garbage collection or to delay the deletion in some way.

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

Sidebar

Related Questions

i have my C# program that can open *.sdf file. i made Associate to
If i have a CSV file that is in the following format fd!,sdf,dsfds,dsfd fd!,asdf,dsfds,dsfd
i have build program that can open *.sdf files and show all the table
I have problem with copying sdf file to WM emulator. My solution structure MyApp.DataLayer
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have application use SDF file and I use System.Data.SqlServerCe, Version 3.5.0.0 I make
I have been surfing for this anwser, but seems like its not supportef in
Is SQL Server Compact Edition Serverless? I mean, If I have a Northwind.sdf file
I have to find a suitable location to deploy my SDF (database) file. The
I have a file that contains lots of insert statements to populate my compact

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.