views:

74

answers:

2

I'm getting this exception when running some code to add text to a Lucene.net index:

The process cannot access the file 'E:\SomeProject\SomeProject.Webroot\App_Data\Lucene\segments.new' because it is being used by another process.

What's the easiest way of finding out what the 'other process' is? (I'm running on Win XP) Here's a stripped down code fragment (the exception is being thrown by the 'AddDocument' line after 50+ iterations) in case that's any help:

using l = Lucene.Net;

public void IndexText(List<TextToIndex> textToIndexList)
{
    l.Analysis.Standard.StandardAnalyzer standardAnalyzer =
        new l.Analysis.Standard.StandardAnalyzer();
    l.Index.IndexWriter indexWriter =
        new l.Index.IndexWriter(_LuceneIndexPath, standardAnalyzer, false);

    foreach (TextToIndex textToIndex in textToIndexList)
    {
        l.Documents.Document luceneDoc =
            CreateLuceneDoc(textToIndex.TypeId,
                textToIndex.TextId,
                textToIndex.Text,
                textToIndex.Title,
                textToIndex.ModifiedDate,
                textToIndex.CultureCode);
         indexWriter.AddDocument(luceneDoc);
    }

    indexWriter.Close();
}
+1  A: 

Try "unlocker" http://ccollomb.free.fr/unlocker/

TheSimon
+2  A: 

You can use sysinternal's (now part of Microsoft) "process explorer" to find out what processes have what files open:

http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

When you run it, click on the "find handle" button (or from the menu find->find handle), then enter "segments.new" - it will show you any processes that have that file open.

KenE