Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Access Database In use or Permission Failure
    text
    copied!<p>I'm using Access 2007 and C# to learn Databases. So far it's been rough but I've been able to handle things relatively well. What I need to do though is to query a my database table Accounts for the Amount of money a user has based on their pin. I've placed a button on the Windows Form I am using that will query the database on click. When I run/click the button as per normal I recieve the following error. </p> <blockquote> <p>Essentially my question is this: How would I go about setting the permissions up so that my program can freely access the Access Database I have?</p> </blockquote> <p>My Exception Error: </p> <blockquote> <p>Exception: System.Data.OleDb.OleDbException: The Microsoft Office Access database engine cannot open or write to the file 'C:\Users\Public'. It is already opened exclusively by another user, or you need permission to view and write its data.</p> </blockquote> <p>My code:</p> <pre><code> public partial class frmPin : Form { static string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Public;Persist Security Info=True"; static private int pin = 11; //The First Pin in my records, for debugging I inserted it directly. static string selectStatement = "SELECT Amount FROM Accounts WHERE(PIN=" + pin + ")"; OleDbConnection conn = new OleDbConnection(connString); OleDbCommand cmd = new OleDbCommand(selectStatement); public frmPin() { InitializeComponent(); } private void btnQry_Click(object sender, EventArgs e) { try { conn.Open(); OleDbDataReader reader = cmd.ExecuteReader(); // executes query while (reader.Read()) // if can read row from database { txtBx.Text = reader.GetValue(1).ToString(); } } catch (Exception ex) { txtBx.Text = "Exception: " + ex; // Displays Exception } finally { conn.Close(); // finally closes connection } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload