locked
System.Data.OleDb.OleDbException: Unspecified error RRS feed

  • Question

  • User-888770435 posted

    I run a web site on windows server 2003 , ii6 asp 2. since 5 years, db  is access

    I face a  probelm the site is crash almost everyday , with the error : System.Data.OleDb.OleDbException: Unspecified   error

    After I restart the IIS service it work OK until the next time.

    I read some form that say to change some definition in the web.config, like  impersonation element - change to False.

    I did it but It crash again.

    Any idea

    Liora

    Wednesday, June 25, 2014 3:46 AM

All replies

  • User-1199946673 posted

    Access isn't really designed for a multi user environment, so also not for web development. However, it can be used, but you need to make sure you open the database connection as late as possible, and close it as soon as possible. Most likely, in 1 or more places in your code, the database will not be closed properly, which will cause problems. The best way is to use the Using pattern, which will ALWAYS close and dispose the connection for you. Code examples:

    http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access

    Wednesday, June 25, 2014 12:57 PM
  • User-888770435 posted

    Do you mean to add  - connection.close() after I finish retrive from database?

    Tuesday, July 1, 2014 3:45 AM
  • User-1454326058 posted

    Hi liora,

    Do you mean to add  - connection.close() after I finish retrive from database?

    Yes, on the other hand, you also need to catch the exceptions, if there are some exceptions, the code connection.close() will not be excuted. You’d better let that code in the finally block.

    Thanks

    Best Regards

    Tuesday, July 1, 2014 5:42 AM
  • User-888770435 posted

    hi,

    Thanks for your reply, Can you remind me how to add the exceptions to the code?

    Wednesday, July 2, 2014 10:09 AM
  • User-1454326058 posted

    Hi liora,

    Please refer to this code:

    SqlConnection con=null;
    try
    {
       con = new SqlConnection(connectionString)
       //other code
    }
    catch(Exception e)
    {
    
    }
    finally
    {
      con.Close();
    }

    On the other hand, you could use the Using to dispose the objects automatically.

    using (SqlConnection con = new SqlConnection(connectionString))
    {
       //other code
       con.Close();//you could remove this code
    }

    Thanks

    Best Regards

    Thursday, July 3, 2014 5:35 AM
  • User-1199946673 posted

    Please refer to this code

    He's NOT using the SQLClient Namespace!!!

    Thursday, July 3, 2014 7:47 PM
  • User-1454326058 posted

    Hi,

    hans_v

    He's NOT using the SQLClient Namespace!!!

    That just a sample about how to handle the error and close the database connection. I focus on that instead of how to connect to the database.

    If you want to know how to connect to the database using OleDbConnection, please refer to this code:

    OleDbConnection connect =null;
    try
    {
      connect= new OleDbConnection("your connection string");
      OleDbCommand command = new OleDbCommand("your sql", connect);
      connect.Open();
      //TODO other code
     }
    catch(Exception err)
    {
      connect.Close();
    }
    

    Thanks

    Best Regards

    Thursday, July 3, 2014 10:14 PM
  • User-821857111 posted

    Do you mean to add  - connection.close() after I finish retrive from database?

    No, not if you open the connection in a using statement as Hans said:

    var query = "SELECT * From Table";
    using(var conn = new OleDbConnection(constring))
    using(var cmd = new OleDbCommand(query, conn)){
        conn.Open();
        //
    }

    As soon as the end of the using block is reached, Close and Dispose is called by the runtime. 

    Friday, July 4, 2014 2:17 AM
  • User-888770435 posted

    I have this sample code, how can I convert it to your code:

    ----------

    m_connection = new OleDbConnection(connectionString);

    string findpage = "SELECT name,contents_" + lang +  

    " FROM pages " +

     "WHERE name='" + PageName + "'" +"; ";  

    OleDbCommand cmdfindpage = new OleDbCommand();

     cmdfindpage.Connection = m_connection;

     cmdfindpage.CommandType = CommandType.Text;

     cmdfindpage.CommandText = findpage;

     OleDbDataReader reader;

     m_connection.Open();

      reader = cmdfindpage.ExecuteReader();

      reader.Read();

      PageText = reader.GetString(1);

    reader.Close();

    ---------------------------------------------------------

    Monday, July 7, 2014 7:10 AM
  • User-1454326058 posted

    Hi liora,

    Please refer to this code:

     

    using(m_connection = new OleDbConnection(connectionString))
    {
    
    string findpage = "SELECT name,contents_" + lang +  
    
    " FROM pages " +
    
     "WHERE name='" + PageName + "'" +"; ";  
    
     OleDbCommand cmdfindpage = new OleDbCommand();
    
      cmdfindpage.Connection = m_connection;
    
      cmdfindpage.CommandType = CommandType.Text;
    
      cmdfindpage.CommandText = findpage;
    
      OleDbDataReader reader;
    
      m_connection.Open();
    
      using(reader = cmdfindpage.ExecuteReader())
      {
    
      reader.Read();
    
      PageText = reader.GetString(1);
    
      reader.Close();
      }
    }
    

    Thanks

    Best Regards

    Monday, July 7, 2014 9:38 PM
  • User-888770435 posted

    Thanks, I will try

    Thursday, July 10, 2014 3:24 AM