Error - System.Data.OleDb.OleDbException: Could not use ''; file already in use. - please help

L

Learner

Hi there,
I am trying to access the access database sitting at

OleDbConnection oleConn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Crystal
Reports\\Samples\\Database\\xtreme.mdb");

and create a crystal report using c#. I have done every thing but for
some reaspon when i try running my webform its throing the below error.
Is there any thing i am missing or need to do some kind of security
settings?

Please help .
thanks in advance
-L

*********************************Error**************************************************
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Could not use '';
file already in use.

Source Error:


Line 39: Dataset1 dataSet = new Dataset1();
Line 40: /* Connect to, fetch data and disconnect from database */
Line 41: oleAdapter.Fill(dataSet, "Customer");
Line 42: /* Use Report Engine object model to pass populated dataset
Line 43: to report */

*************************************End of the
error***********************************
 
J

Joey

Apparently the Access database is still open and locked for exclusive
use by something.

Are you accessing it from your app a second time (during the same run)
here? If so then make sure you are explictly closing the connection
from the first time.
 
L

Learner

I think i am doing it right. But still i am not sure though. Here is
the code i am using...

oRpt = new CustomerSales ();
/* Use ADO.NET object model to set up connection information */
OleDbConnection oleConn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Crystal
Reports\\Samples\\Database\\xtreme.mdb");
OleDbDataAdapter oleAdapter = new OleDbDataAdapter("SELECT * FROM
Customer", oleConn);
Dataset1 dataSet = new Dataset1();
/* Connect to, fetch data and disconnect from database */
oleAdapter.Fill(dataSet, "Customer");

/* Use Report Engine object model to pass populated dataset
to report */
oRpt.SetDataSource (dataSet);
/* bind report object with data to the Web Forms Viewer */
CrystalReportViewer1.ReportSource = oRpt;
 
J

Joey

put...

oleConn.Close();

....after the oleAdapter.Fill(dataSet, "Customer"); line. I think you
need to explicitly close the connection to the database each time,
unless you modify the command behavior to do it automatically.
 
L

Learner

HI joey,
I thought i already replied to it. I am sorry about that. Yes it did
work for me and my bad i never closed the connection object.
thanks for the help
-L
 
G

George Ter-Saakov

PS: make sure your ASP account can create files in the same folder you MDB
file is.
Access driver creates ldb file which has locking information. Without it
your database will be opened in single user mode

George.
 
G

Guest

I think it is not a real OleDbException. It is a matter of privilege.
You need to give the ASP account privilege to the folder at which the
xtreme.mdb file resides or move the file into the solution folder.
 

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

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top