Accessing NORTHWND.MDF

G

Gordon Padwick

I'm in the process of learning WPF and have been using NORTHWND.MDF while
becoming familiar with ADO.NET. All has worked well until a couple of days
ago. Now NORTHWND.MDF is no longer accessible, whereas PUBS.MDF works fine.

My simple code is:

class Program
{
static void Main(string[] args)
{
SqlConnection thisConnection = new SqlConnection(
@"Data Source=.\SQLEXPRESS;" +
@"AttachDbFilename='C:\SQL Server 2000 Sample
Databases\NORTHWND.MDF';" +
@"Integrated Security=True; Connect Timeout=30; User
Instance=True");
thisConnection.Open();
}
}

This code runs for a few seconds and then"DataReading has stopped working"
appears. After changing NORTHWND.MDF to PUBS.MDF in the code, all is fine.

I came to the conclusion that NORTHWND.MDF must be corrupt, so I decided to
delete it and then download a new version. When I tried to delete the file I
saw the message "The action can't be completed because the file is open in
another program. Close the file and try again."

I thought that maybe SQL Server Express had the file open, but I can't find
SQL Server Express on my computer.

Can anyone suggest how I can close the file when I don't know what program
has it open or whatever else I might try to get this simple code working
again?

Gordon
 
P

Peter Duniho

Gordon said:
[...]
I came to the conclusion that NORTHWND.MDF must be corrupt, so I decided
to delete it and then download a new version. When I tried to delete the
file I saw the message "The action can't be completed because the file
is open in another program. Close the file and try again."

I thought that maybe SQL Server Express had the file open, but I can't
find SQL Server Express on my computer.

SQL Server Express runs as a service. There's a configuration console
(should be available in your Start menu), and of course you can control
it with the Services control panel.
Can anyone suggest how I can close the file when I don't know what
program has it open or whatever else I might try to get this simple code
working again?

If it's indeed SQL Server Express that is keeping the file open (I don't
know that it would be), you may be able to release the file by stopping
the SQL Server Express service. Alternatively, rebooting in the most
minimal Safe Mode may disable whatever process is keeping it open,
whether that's SQL Server Express or not.

Barring that, there are lots of other "hiccups" that can cause a file to
appear locked to Windows, some involving quite a bit of difficulty to
resolve. And none having anything to do with C# or .NET.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top