Groups | Blog | Home
all groups > dotnet faqs > march 2004 >

dotnet faqs : Using Access with C#.NET



Curt Emich
3/17/2004 6:33:17 PM
I'm tyring to use MS Access with .NET, but I'm having some problems. Here's
the code:



string sSQL = "SELECT Statement_Id,Statement_In_Brief FROM Statements";

OleDbDataAdapter thisAdapter = new OleDbDataAdapter(sSQL,oleDbConnection1);

DataSet thisDataset = new DataSet();

thisAdapter.Fill(thisDataset,"Statements");



It bombs on the 4th line. I get the error message, "

The Microsoft Jet database engine cannot open the file
'C:\Inetpub\wwwroot\TrainOfThought\data\TrainOfThought.mdb'. It is already
opened exclusively by another user, or you need permission to view its data.
It is not opened by another user, etc. Something else is going on. Does
anyone have any ideas as to what that might be? Thanks in advance for your
help.



William Ryan eMVP
3/17/2004 6:36:52 PM
can you open it manually?
[quoted text, click to view]

Paul Clement
3/18/2004 9:44:54 AM
[quoted text, click to view]

¤ I'm tyring to use MS Access with .NET, but I'm having some problems. Here's
¤ the code:
¤
¤
¤
¤ string sSQL = "SELECT Statement_Id,Statement_In_Brief FROM Statements";
¤
¤ OleDbDataAdapter thisAdapter = new OleDbDataAdapter(sSQL,oleDbConnection1);
¤
¤ DataSet thisDataset = new DataSet();
¤
¤ thisAdapter.Fill(thisDataset,"Statements");
¤
¤
¤
¤ It bombs on the 4th line. I get the error message, "
¤
¤ The Microsoft Jet database engine cannot open the file
¤ 'C:\Inetpub\wwwroot\TrainOfThought\data\TrainOfThought.mdb'. It is already
¤ opened exclusively by another user, or you need permission to view its data.
¤ It is not opened by another user, etc. Something else is going on. Does
¤ anyone have any ideas as to what that might be? Thanks in advance for your
¤ help.

Very likely a permissions issue. Make certain that you have Read, Write, Create, and Modify
permissions to the folder where the database is located.

If this is web app you will probably need to provide these permissions to the ASPNET account,
although it will also depend upon what type of authentication you are using for your ASP.NET
application.


Paul ~~~ pclement@ameritech.net
Curt Emich
3/18/2004 10:22:43 PM
I reluctantly gave the folder those permissions -- it causes a security
vulnerability when you allow execute permissions on a folder.

Still, at least I can get to the data. I thought I had to use a data
adapter, but I have the book "Professional C# 2nd Edition" and on pages
775-778, there is clearly an example of a program that uses Access and
still uses datasets.

I followed that example almost line for line, but I still have a
dropdown listbox that won't populate. Here's the code:



private void Page_Load(object sender, System.EventArgs e)
{

string sSQL = "SELECT Statement_Id,Statement_In_Brief FROM
Statements";
daStatements = new OleDbDataAdapter(sSQL,oleDbConnection1);
daStatements.Fill(dsStatements,"Statements");
DropDownList1.DataSource = dsStatements.Tables["Statements"];

DropDownList1.DataBind();

Response.Write("test");

} // end PageLoad event



I get NO build errors on this code, yet I get an empty dropdown list
box. Not only that, but "Response.Write" and "Console.Writeline" don't
write anything anywhere that I can see. I'm finding it difficult to do
diagnostics when I can't write messages to the screen anywhere. Any
clues? Thanks in advance for your help.



Remulac

*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button