Hello Frends,

I have an application where I am trying to connect MS Access DB with a ASP.Net(C#) Page and the same application also connect to the MS SQL Server (Working Fine). While connecting I am having following error:


_____________________________________________________________________________________

Server Error in '/manager' Application.
The Microsoft Jet database engine cannot open the file 'C:\Inetpub\vhosts\\httpdocs\manager'. It is already opened exclusively by another user, or you need permission to view its data.

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: The Microsoft Jet database engine cannot open the file 'C:\Inetpub\vhosts\\httpdocs\manager'. It is already opened exclusively by another user, or you need permission to view its data.

Source Error:

Line 28: conna = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " +Server.MapPath(ct));
Line 29: comm = new OleDbCommand("Select * from stockin where sl="+Request.QueryString["id"]+" ", conna);
Line 30: conna.Open();
Line 31: dr = comm.ExecuteReader();
Line 32: //DataGrid1.DataSource = dr;


Source File: c:\inetpub\vhosts\\httpdocs\manager\Off_customer_ Line: 30

Stack Trace:

[OleDbException (0x80004005): The Microsoft Jet database engine cannot open the file 'C:\Inetpub\vhosts\\httpdocs\manager'. It is already opened exclusively by another user, or you need permission to view its data.]
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +969373
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +86
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +29
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +4863644
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.OleDb.OleDbConnection.Open() +40
Off_customer_joining.Page_Load(Object sender, EventArgs e) in c:\inetpub\vhosts\\httpdocs\manager\Off_customer_
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

_____________________________________________________________________________________

Points to be noted: I am Using a shared server of a hosting company.

Below the code I am using,

protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoServerCaching();
        HttpContext.Current.Response.Cache.SetNoStore();
        String ct;
        ct = Request.QueryString["ct"];

        OleDbConnection conna;
        OleDbCommand comm;
        OleDbDataReader dr;
        conna = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " +Server.MapPath(ct));
        comm = new OleDbCommand("Select * from stockin where sl="+Request.QueryString["id"]+" ", conna);
        conna.Open();
        dr = comm.ExecuteReader();
        //DataGrid1.DataSource = dr;
        //DataGrid1.DataBind();
        //foreach (DataRow row in dr.Tables[0].Rows)
        //{
            //txt_form.Text = row[0].ToString();
            //txt_name.Text = row[1].ToString();
            //txt_instamt.Text = row[2].ToString();
            //txt_term.Text = row[3].ToString();
            //txt_scheme.Text = row[4].ToString();

        //}
        txt_form.Text = dr["formno"].ToString();
        conna.Close();

Waiting for valuable suggestions!!

Dani AI

Generated

Quick diagnosis and first check: the exception shows the Data Source resolving to “…\httpdocs\manager” (a folder), not to an Access file. The Jet provider expects the full path and filename of the .mdb/.accdb file in the connection string, so confirm what Server.MapPath(ct) actually returns and make sure Data Source points to the actual database file (for example .../manager/mydb.mdb). Server.MapPath maps a virtual path to a physical path; Jet/ADO.NET connection strings require a file path in Data Source. (learn.microsoft.com)

Practical fixes (safe, disposable usage and parameterization):

string dbFile = Server.MapPath(Request.QueryString["ct"]); // validate this is a .mdb/.accdb path
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbFile + ";";

using (var conn = new OleDbConnection(connStr))
using (var cmd = new OleDbCommand("SELECT formno FROM stockin WHERE sl = ?", conn))
{
    cmd.Parameters.AddWithValue("?", Request.QueryString["id"]); // OleDb uses ? placeholders (order matters)
    conn.Open();
    using (var rdr = cmd.ExecuteReader())
    {
        if (rdr != null && rdr.Read())
            txt_form.Text = rdr["formno"].ToString();
    }
}

Note: OleDbCommand with CommandType.Text uses positional ? parameters, and a DataReader must be advanced with Read() before column access. Using using ensures proper disposal. (learn.microsoft.com)

File-lock / permission checklist (common on shared hosts): Access creates a .ldb or .laccdb lock file in the same folder and requires that the process can create/read/delete files there. If the web process cannot create the lock file (or another process has opened the DB with exclusive access), Jet will throw this error. Confirm the database file exists, check for an existing lock file, and verify the web app identity has Read/Write/Create/Delete on the DB folder (on IIS grant permissions to the appropriate app-pool identity such as IIS APPPOOL\<AppPoolName> or ask hosting support to set these ACLs). (learn.microsoft.com)

Platform and hosting notes: Microsoft.Jet.OLEDB.4.0 is a 32-bit provider. On 64-bit hosting either enable 32-bit mode for the AppPool or use the ACE provider (Access Database Engine) if available — on many shared hosts this requires support from the provider. If problems persist after correcting the path and permissions, request the host to confirm file ACLs and whether the environment supports Jet/ACE for the app pool. (learn.microsoft.com)

Acknowledgement: original stack trace shows the folder-based path; ’s pointer to Microsoft support is relevant for lock/permission scenarios, but confirming the mapped path, fixing the connection string, using parameterized commands, and checking app-pool permissions will typically resolve this error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.