none
Access System.Data.OleDb.OleDbException: Unspecified error RRS feed

  • Question

  • I have a Windows Forms application using c# and .NET OleDb and Access database and getting the following error on select statements

    "Select * From ContactsTable Where Number = 927", the strange thing this is occurring only if I compile the program, it always runs fine when I run it in Visual Studio 2010 IDE.  I have tried to compact and repair the database, but that does not help. I have seen a lot of references about this error to ASP.NET, but mine app is a Windows Forms app.

     

    Does anyone have a solution to this problem?

    Here is the error:

    System.Data.OleDb.OleDbException: Unspecified error

       at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)

       at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)

       at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)

       at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)

       at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)

       at System.Data.OleDb.OleDbConnection.Open()

       at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)

       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)

       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)


    Peter
    Sunday, August 21, 2011 12:56 PM

Answers

  • Hi Peter,

    Thanks for your code.

    I think there isn't need to open the connection by yourself.

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

    The Fill method retrieves the data from the data source using a SELECT statement. The IDbConnection object associated with the select command must be valid, but it does not need to be open. If the IDbConnection is closed before Fill is called, it is opened to retrieve data and then closed. If the connection is open before Fill is called, it remains open.

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

    Please feel free to try any Cup target.

    Have a nice day.

     


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by pczurak Wednesday, August 24, 2011 1:50 AM
    Tuesday, August 23, 2011 7:56 AM
    Moderator

All replies

  • Hi Peter,

    Welcome!

    >>it always runs fine when I run it in Visual Studio 2010 IDE

    It means the form can show the right records? Would you please share some code with us. I think you problem may relates to Platform target.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 22, 2011 12:30 PM
    Moderator
  • I'm surprised it actually runs in the IDE. The keyword "Number" is a reserved word in Jet/ACE SQL. You can enclose it in brackets in the SQL statement but a better solution would be to rename it.

    List of Microsoft Jet 4.0 reserved words 


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Monday, August 22, 2011 3:34 PM
  • I'm surprised it actually runs in the IDE. The keyword "Number" is a reserved word in Jet/ACE SQL. You can enclose it in brackets in the SQL statement but a better solution would be to rename it.

    List of Microsoft Jet 4.0 reserved words 


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Actually the exact SQL I am using is

    "Select * From ContactsTable Where MillNumber = 927"

    The SQL is not the problem.


    Peter
    Tuesday, August 23, 2011 3:05 AM
  •  

    Here's my code:
    The project is compiled as 86x and it runs fine in IDE and runs fine on 64bit Windows 7 stand alone, but not on Windows 7 32bit stand alone

      public OleDbDataAdapter OleDbAdapter(string query, DataSet ds, string tableName)
      {
       var adapter = new OleDbDataAdapter();
       try
       {
        if (_tsrConnection == null)
        {
         _tsrConnection = new OleDbConnection(_connectionString);
         _tsrConnection.Open();
        }
        adapter.SelectCommand = new OleDbCommand(query, _tsrConnection);
        adapter.Fill(ds, tableName); // <-- this is where the error occurs
       }
       catch (Exception e)
       {
        throw new Exception(string.Format("{0}: {1}{1}", query, Environment.NewLine), e);
       }
       return adapter;
      }
    

     

    also if I comment out the   //if (_tsrConnection == null) the error occurs on _tsrConnection.Open();

     

            public OleDbDataAdapter OleDbAdapter(string query, DataSet ds, string tableName)

            {

                var adapter = new OleDbDataAdapter();

                try

                {

                    //if (_tsrConnection == null)

                    {

                        _tsrConnection = new OleDbConnection(_connectionString);

                        _tsrConnection.Open(); // <-- error occurs here

                    }

                    adapter.SelectCommand = new OleDbCommand(query, _tsrConnection);

                    adapter.Fill(ds, tableName); 

                }

                catch (Exception e)

                {

                    throw new Exception(string.Format("{0}: {1}{2}", query, Environment.NewLine, e));

                }

                return adapter;

            }

     

     


    Hi Peter,

    Welcome!

    >>it always runs fine when I run it in Visual Studio 2010 IDE

    It means the form can show the right records? Would you please share some code with us. I think you problem may relates to Platform target.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.



    Peter
    Tuesday, August 23, 2011 4:34 AM
  • Hi Peter,

    Thanks for your code.

    I think there isn't need to open the connection by yourself.

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

    The Fill method retrieves the data from the data source using a SELECT statement. The IDbConnection object associated with the select command must be valid, but it does not need to be open. If the IDbConnection is closed before Fill is called, it is opened to retrieve data and then closed. If the connection is open before Fill is called, it remains open.

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

    Please feel free to try any Cup target.

    Have a nice day.

     


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by pczurak Wednesday, August 24, 2011 1:50 AM
    Tuesday, August 23, 2011 7:56 AM
    Moderator
  • OK, well you sure faked me out. I would check folder permissions (full permissions are required), especially if the database is in a different location when run outside of the IDE.
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Tuesday, August 23, 2011 12:01 PM
  • OK, well you sure faked me out. I would check folder permissions (full permissions are required), especially if the database is in a different location when run outside of the IDE.
    Paul ~~~~ Microsoft MVP (Visual Basic)

    It's the same location same user.

    I have several tables and the same type of query is called on each one and this error occurs on each one of those tables but on different one (seemingly at random) every time I run the program.  I don't think it's at random I think there is some kind of pattern, but I can't figure it out. 


    Peter
    Tuesday, August 23, 2011 12:14 PM
  • Do you run Visual Studio "as an Administrator"?
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Tuesday, August 23, 2011 12:34 PM
  • Do you run Visual Studio "as an Administrator"?
    Paul ~~~~ Microsoft MVP (Visual Basic)
    No, running as normal user.
    Peter
    Tuesday, August 23, 2011 1:03 PM
  • Where is the database located? Is it in a Documents folder? If not, I would try moving it there to see if it makes any difference.
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Tuesday, August 23, 2011 1:22 PM
  • Where is the database located? Is it in a Documents folder? If not, I would try moving it there to see if it makes any difference.
    Paul ~~~~ Microsoft MVP (Visual Basic)
    I have tried that already and getting the same results.
    Peter
    Tuesday, August 23, 2011 2:19 PM
  • I'm out of suggestions, other than to try monitoring the application process using the Process Monitor utility to see if any system related errors occur.

    One other suggestion, make sure to close your connection when you're finished with the database operation. There's no reason really to maintain a persistent connection to an Access database.


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Tuesday, August 23, 2011 10:42 PM
  • Hi Peter,

    Thanks for your code.

    I think there isn't need to open the connection by yourself.

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

    The Fill method retrieves the data from the data source using a SELECT statement. The IDbConnection object associated with the select command must be valid, but it does not need to be open. If the IDbConnection is closed before Fill is called, it is opened to retrieve data and then closed. If the connection is open before Fill is called, it remains open.

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

    Please feel free to try any Cup target.

    Have a nice day.

     


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    That was the problem, don't know why it worked in IDE, but not stand alone. Once I commented out Open() statement everything worked.

     

    Thank You


    Peter
    Wednesday, August 24, 2011 1:49 AM
  • Alan Chen's solution fixed the problem.

    Thank you for all of your help.


    Peter
    Wednesday, August 24, 2011 1:51 AM