Thread: "could not lock file" error using asp.net

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    Post "could not lock file" error using asp.net

    I working on c# project and I get a error whenever I try to open the connection to a MS Access file. The error reads "Could not lock file". This is an ASP.net project. I am using visual studio .net. I have tried the same code in a windows application in c# and it works just fine. I have gave permissions to the ASPNET user to this file and folder to include write permissions. I have also added the ASPNET user permissions to IIS. Can someone please help me out with this. Below is the code:

    Code:
    private void btnSubmit_Click(object sender, System.EventArgs e)
    {
       try
       {
          string strSql = "";
          string strConnectionString = "";
          strSql = "SELECT * FROM Orders";
    
          strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=D:\\Databases\\Northwind.mdb;Mode=Share Deny None;Persist Security Info=False";
    	        
          OleDbConnection conn = new OleDbConnection(strConnectionString);
       
          OleDbDataAdapter da = new OleDbDataAdapter(strSql, conn);
          DataSet ds = new DataSet();
    
          conn.Open();
          da.Fill(ds);
          conn.Close();
    
          this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
          this.DataGrid1.DataBind();
       }
       catch(Exception err)
       {
          this.lbl1.Text = err.Message;
       }
                		
    }
    zMan

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    Error

    Below is the error that I get... I have tried using different databases and it does it with all of them.

    Server Error in '/WebApplication3' Application.
    --------------------------------------------------------------------------------

    Could not lock file.
    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: Could not lock file.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:


    [OleDbException (0x80004005): Could not lock file.]
    System.Data.OleDb.OleDbConnection.ProcessResults(I nt32 hr)
    System.Data.OleDb.OleDbConnection.InitializeProvid er()
    System.Data.OleDb.OleDbConnection.Open()
    WebApplication3.WebForm1.btnSubmit_Click(Object sender, EventArgs e)
    System.Web.UI.WebControls.Button.OnClick(EventArgs e)
    System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
    System.Web.UI.Page.ProcessRequestMain()




    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
    zMan

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Give full access permissions to the parent folder. See Q306441.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    31
    I don't really have any idea but I have done this for you, but by using SqlConnection,SqlAdapter. Control . you can change your own to satisfy this .

    Also I have submit full example ( from DEITEL C# How to Program book ) on (OLE) and also the access data base.


    Code:
    // this method for none query ( insert,delete,update)
    		public void EditingQuery (string NonQuery)
    		{	
    			try
    			{
    
    System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand();
    				Command.Connection = this.sqlConnection1;
    				Command.CommandText = NonQuery;
    				Command.Connection.Open();
    				Command.ExecuteNonQuery();
    				Command.Connection.Close();
    			}
    			catch (System.Exception ex )
    			{
    
    		//	Session.Add("Error","EditingQuery:"+ex);
    				
    			}
    		}
    		
    			
    
    // this method for query, all you have to do is to submit the query like
    // string query = " SELECT * FROM Mytable";
    // Query(query);
    
    			public void Query ( string query)
    			{
    			try
    			{
    					this.sqlConnection1.Open();
    					this.dataSet1.Clear();
    					this.sqlDataAdapter1.SelectCommand.CommandText= query;
    					this.sqlDataAdapter1.Fill(dataSet1,"table");
    					this.sqlConnection1.Close();
    
    				}
    				catch (System.Exception ex )
    				{
    				//	Session.Add("Error","Query:"+ex);
    					
    			}
    			}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lock needed in this scenario?
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-25-2008, 07:22 AM
  2. read write lock in C#
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 04-16-2008, 08:49 AM
  3. Atomic Operations
    By Elysia in forum Windows Programming
    Replies: 27
    Last Post: 03-27-2008, 02:38 AM
  4. nested lock?
    By George2 in forum C# Programming
    Replies: 2
    Last Post: 03-23-2008, 08:33 AM
  5. Threading and mutex's
    By megatron09 in forum C++ Programming
    Replies: 14
    Last Post: 09-07-2006, 02:40 PM