YZlat
asked on
Could not use ''; file already in use error when opening Access database
I have a dropdown on my page that gets populated from Access dataabse. I am not using AccessDataSource but instead just using OleDbConnection object. I keep getting "Could not use ''; file already in use" error. Sometimes it works but most of the time that error comes up. I gave ASPNET user full control to the folder where my mdb file is stored.
here is my connection string and code below:
<add name="conn" connectionString="Provider =Microsoft .Jet.OLEDB .4.0;Data Source=C:\Northwind.mdb;" providerName="System.Data. OleDb"/>
here is my connection string and code below:
<add name="conn" connectionString="Provider
public OleDbConnection GetConnection(string strConn)
{
OleDbConnection conn = null;
try
{
conn = new OleDbConnection(strConn);
conn.Open();
}
catch (OleDbException ex)
{
Console.Write("OleDb ERROR: " + ex.Message);
}
catch (Exception ex)
{
Console.Write("ERROR: " + ex.Message);
}
return conn;
}
ASKER
The Access application is closed at all times and I do clode the connection after reading data;
cmd.ExecuteReader(CommandB ehavior.Cl oseConnect ion);
cmd.ExecuteReader(CommandB
are you closing your data reader? I meant closing your .net application and the access application. close your asp.net development servers sitting in the system tray and try deleting the lock files if any.
ASKER
Yes, I am closing the data reader.
Also what i noticed is that sometimes app loads data into dropdown fine and when I select an item from a dropdown, it displays data on the page, but if I try to select another item the second time around, it also gives me this error. What can i do to fix it?
Also what i noticed is that sometimes app loads data into dropdown fine and when I select an item from a dropdown, it displays data on the page, but if I try to select another item the second time around, it also gives me this error. What can i do to fix it?
Hi,
You didn't respond for link.
Regards,
VSS
You didn't respond for link.
Regards,
VSS
Could you post your code ? So we could understanding what is happening around
ASKER
public OleDbDataReader ExecuteSimpleQuery(string query, string strConn)
{
OleDbConnection conn = GetConnection(strConn);
OleDbDataReader rdr = null;
try
{
using (OleDbCommand cmd = new OleDbCommand(query, conn))
{
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
}
catch (Exception ex)
{
Console.Write("Error executing query " + query + ": " + ex.Message);
rdr.Close();
rdr = null;
}
return rdr;
}
ASKER
vs00saini, the database is not on the server. Instead it's on the same machine as the web application. It's an access database
Hi,
I agree that database is not on the server. But however you are creating web application. Then either you are using inbuilt server of VS or your system would be considered as server in that case.
Is your same folder is having .ldb files to prevent different users to access same resource at a time.
Regards,
VSS
I agree that database is not on the server. But however you are creating web application. Then either you are using inbuilt server of VS or your system would be considered as server in that case.
Is your same folder is having .ldb files to prevent different users to access same resource at a time.
Regards,
VSS
ASKER
It's not a permissions issue, i checked before I posted the question here
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I actually didn't have to change anything in my code, it just started working
FINALLY SOLUTION ALSO FOR ME.
To reset all resources, posted by Vikram was helpful form.
To reset all resources, posted by Vikram was helpful form.
You would find a mdb lock file under the the same folder where ur mdb file is sitting. please delete that file and you should be all set.
If you are not able to delete the file. close the application and try.