Problems using VS.Net to Open Access 2000 Database

Status
Not open for further replies.

kaanbl

Seniorius Lurkius
12
I am working on a personal website using VS.NET (C# programming language) and I have a small Access 2000 Database I am trying to connect to. I am using XP Pro Operating System. I created the connection using Server Explorer and added it to the Web Form. When I try to open the connection, it throws the following error:
The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data.

I have checked the permissions on the Web Sites Folder, Default Web Site, the root directory, the folder the database is in and the database file itself and have set permissions for all of these to Read/Write, Execute Permissions: Scripts only and it is still throwing the above error.

Any thoughts????????
 

Handor

Ars Tribunus Militum
2,513
Maybe a long shot... have you got the database open in design mode when you are doing this?

Oh, there's one other possibility you might try, too. If the answer to the above is negative, close Visual Studio and run the compiled binary directly. Might be that, somehow, since you're working in the Server Explorer, your opening a connection to the db that it doesn't release when you run the app, and hence blocks you from using it with exclusive access.

That's all I can think of off the top of my head. The solution, if that is the case, is to get out of the db in the Server Explorer.
 

Handor

Ars Tribunus Militum
2,513
OK, two more things you might try:

Go to the directory with the database in it (should be .mdb). See if there's a .ldb file of the same name in the directory. If there is, change its name (in case you ever want to put it back-- you shouldn't need to, but you might want the peace of mind) to something like <whatever>.ldb.bak and try re-running your program.

Alternately, and this is a long shot, find out if VS.Net's connection used ODBC to get to the file, or opened it directly. If the latter, delete any ODBC connections pertaining to that file.
 

kaanbl

Seniorius Lurkius
12
I didn't see a .ldb file and I tried something different. I deleted the connection I created with VS.Net and just programmed the connection myself in the process requiring the open connection. Now I am getting this error:

Operation must use an updateable query.

From looking on-line this is usually associated with a permissions setting being incorrect somewhere. I am new to IIS and and am trying to understand what and where all the permissions need to be set (I thought I had them all set correctly). Here is a snippet of code:

private void btn_Guest_Book_Click(object sender, System.EventArgs e)
{
string ConnStr ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Inetpub\\wwwroot\\HomePage\\homepage.mdb";

string dateString = DateTime.Now.ToLongTimeString();

string insertGuest = "INSERT INTO Guestbook (name, insert_date, email, home_page_url, comments) " +
"VALUES ('" + Name.Text + "', '" + dateString + "', '" + Email.Text + "', '" + HomePage.Text + "', '" + Comments.Text + "')";

System.Data.OleDb.OleDbConnection HomePageConnection = new System.Data.OleDb.OleDbConnection(ConnStr);

System.Data.OleDb.OleDbCommand insertCommand = new System.Data.OleDb.OleDbCommand(insertGuest, HomePageConnection);

HomePageConnection.Open();

int queryResult = insertCommand.ExecuteNonQuery();
//this is the line that it is now failing

if (queryResult == 1)
{
resultLabel.Text = "Your entry has been added. Thank You!";
}

}

I do appreciate the help received and any other suggestions that might come this way in the future.
 
Status
Not open for further replies.