Link to home
Start Free TrialLog in
Avatar of purdyra1
purdyra1Flag for United States of America

asked on

Why??? process cannot access the file because it is being used by another process

I have a web app I am running.  all of my other web pages work just fine and access the database just fine.  but when I click on a new page I get this error.  I can then go out and access other pages that access db just fine again.

I must add, the other pages use regular data calls, but this 'problem' page is using Linq.

I look in the sql log and see:


2010-04-20 18:03:28.90 Logon       Login failed for user 'WORKLAPTOP\username'. [CLIENT: <named pipe>]
2010-04-20 18:04:13.53 spid51      Error: 17207, Severity: 16, State: 1.
2010-04-20 18:04:13.53 spid51      FCB::Open: Operating system error 32(The process cannot access the file because it is being used by another process.) occurred while creating or opening file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\db1.mdf'. Diagnose and correct the operating system error, and retry the operation.

I did go into my:
C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS
and delete everything and restart.

thx.
Avatar of purdyra1
purdyra1
Flag of United States of America image

ASKER

oh, also I look at the code as I walk thru it and the error I see is:

[0] = {System.Data.SqlClient.SqlError: Cannot open user default database. Login failed.}
[1] = {System.Data.SqlClient.SqlError: Login failed for user cpuname\username'.}
Avatar of Anthony Perkins
Please post your connection string.  I suspect you are trying to attach the database as opposed to merely opening it.
On second thoughts, does the default database for cpuname\username exist?  If not change it to a database that does exist, Master for example.
since I am using a sourcesafe I have to share the .mdf with the rest of the team, so I do have to keep attaching and detaching the mdf to check it in.  the default db was the db that we are using and I thought, well maybe behind the scenes this is causing problems, so I made the default db for the cpuname\username the Master Db, this way if I detach the db we are using it doesn't cause problems.

so to answer your question, the default db is Master.
I was told that linq doesn't look at the app.config file where the other connection string is. it has the same values either way.
this is from the Settings.settings file.

here is the connection string:

<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="example1.Core.Properties" GeneratedClassName="Settings">
  <Profiles />
  <Settings>
    <Setting Name="example1ConnectionString" Type="(Connection string)" Scope="Application">
      <DesignTimeValue Profile="(Default)"><?xml version="1.0" encoding="utf-16"?>
<SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <ConnectionString>Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\example1.mdf";Integrated Security=True;User Instance=True</ConnectionString>
  <ProviderName>System.Data.SqlClient</ProviderName>
</SerializableConnectionString></DesignTimeValue>
      <Value Profile="(Default)">Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\example1.mdf";Integrated Security=True;User Instance=True</Value>
    </Setting>
  </Settings>
</SettingsFile>
whoops, one of my examples above says  db1.mdf, and the other has example1.mdf.

I obviously am just replacing the real name of the db to something I am making up.  they should be the same and in my code they are. so ignore this oversight.
>>since I am using a sourcesafe I have to share the .mdf with the rest of the team, so I do have to keep attaching and detaching the mdf to check it in.<<
Then that is your problem.  There is simply no need to do that.  I am surprised you have not corrupted the database yet.
why does it work for the rest of our web pages except for this one page? besides the fact the others don't use Linq and this one does?

we are all working remotely on our machines at our homes, and due to the situation we have to have a local install of the .mdf file.
I have to download the changes to the .mdf from the other users, and to do that, I must detach the db or it won't let me download a file becz it's in use.

any other workarounds?
and I keep thinking to myself, it works just fine with the other pages just fine, except for this one page that uses Linq.
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial