2009-04-06 2 views
0

저는 데이터베이스를 배우기 위해 Access 2007과 C#을 사용하고 있습니다. 지금까지 그것은 거칠었지만 나는 비교적 잘 처리 할 수있었습니다. 내가해야 할 일은 내 데이터베이스 테이블을 쿼리하는 것입니다. 사용자가 핀을 기준으로 계산 한 금액을 계산합니다. 클릭 할 때 데이터베이스를 쿼리하는 Windows Form에 단추를 배치했습니다. 정상/당 버튼을 클릭하거나 실행하면 다음 오류가 나타납니다. C# 데이터베이스 사용 중 또는 사용 권한 오류

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?

내 예외 오류 :

내 코드

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.

:

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 
     } 
} 

답변

1

"C : \ 사용자가 공용을 \"는 * .mdb 파일의 실제 경로로 변경해야 액세스하려는 :

"C : \ Users \ Public.mdb"

또는

: 데이터베이스의 이름에 따라

"C 공공 \ Something.mdb \ \ 사용자"

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=; 

아니면이 * .accdb 파일이 될 수 있습니다. 예를 들면 :

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False; 

http://www.connectionstrings.com/access-2007http://www.connectionstrings.com/access 또한

를 참조하면 액세스 2007과 같은 다른 프로그램에서 파일을 열고있는 경우, 때때로 당신은 이런 종류의 문제를 얻을 것이다, 파일은 읽기 전용으로 표시, 또는 보안 권한은 사용자가 읽기 또는 쓰기 액세스 권한이없는 것과 같습니다. 사용자와 같은 그룹에 대한 "거부"권한 (파일 시스템/NTFS)을 설정하면 관리자가 거부 권한에 의해 영향을 받도록 다른 모든 권한이 무시됩니다.

편집 : 의견을 주셔서 감사합니다. 약간의 설명이 추가되었습니다.

+0

아, 파일 자체를 포함시켜야합니다. 도움을 주셔서 대단히 감사합니다. – Xesaniel

+0

* .accdb 파일 인 경우 사용자 수준 보안이 엔진에서 제거되었으므로 그룹/사용자에 대한 권한을 거부 할 수 없습니다. – onedaywhen

+1

Jet ULS에는 DENY 권한이 없었기 때문에 aaronis가 NTFS 보안을 언급하고 있음이 분명합니다. –