# Visual Basic > Visual Basic FAQs >  Database - What does this error mean, and how do I fix it?

## si_the_geek

The following is a list of database related errors that often appear on the forums, along with an explanation of what the errors mean and suggestions for how to solve them.

First of all please note that list is for errors that occur when specifically working with databases/data, so if your error is occurring in "normal" code the advice here (even if it has the same error message) is unlikely to be entirely relevant/accurate. If this is the case, please see the advice that follows the list.


Error messages can vary by database system & connection technology, so the text in the message may differ slightly from what is listed – but the cause/solution are likely to be the same.
Contents
"Could not find installable ISAM""Data source name not found and no default driver specified."
"Syntax error in .. clause""No value given for one or more required parameters.""Too few parameters. Expected ..."
".. Type mismatch .."
"String or Binary data would be truncated""The field is too small to accept the amount of data..."
"Item cannot be found in the collection corresponding to the requested name or ordinal""Item not found in this collection"
"Either BOF or EOF is True..."
"Operation is not allowed when the object is closed.""Operation is not allowed when the object is open.""The connection cannot be used to perform this operation. It is either closed or invalid in this context."
"Unrecognized database format"
"Multi-step OLE DB operation generated errors. ..."

*Something not listed here?   Suggestions didn't help?*
If your problem wasn't listed above (or the suggestions didn't solve the problem), there is still hope!

If you are using Classic VB (_VB6 or earlier, or the VB editor in an Office application_) then see if the error is in the Classic VB equivalent of this page, which can be found here.

For errors relating to code that is not specifically working with data in/from a database, please see the appropriate FAQ page for your environment (such as the Classic VB FAQs for VB6 or earlier, or the Office Development FAQs for an Office program).

For errors that are data/database related...
If your error is not listed above, see if there is a separate article for it within our Database Development FAQ's _(as it may be a Database/Language specific issue)_.
For problems with SQL statements, see if _How can I find out why my SQL isn't working?_ helps.
If you still need help, please post the details as a new thread in our Database Development forum, including as much detail as you can (see here for the kind of info we are likely to need).

----------


## si_the_geek

*"Could not find installable ISAM"*
*"Data source name not found and no default driver specified."*
_What it means:_Either your connection details (or connection string) are incorrect, or the driver you are trying to use is not installed on the computer.

_How to solve it:_First of all check that your connection details (or connection string) are correct, even if they were working before and you think you haven't changed them.   If you are getting part of them from user input, make sure that the values are validated and used appropriately.

Once you are sure that your connection details are correct, ensure the required software is installed.  It is generally best to start by installing MDAC (as this updates ADO etc, and installs some Microsoft drivers), details of which can be found here; if using a Jet database (Access/Excel/CSV/...) you should also install the Jet or ACE drivers (the previous link includes a downloads these).

For non-Microsoft database systems (eg: Oracle/MySQL/...) you are likey to need to install specific drivers, details of which can usually be found on the company website (the names of the drivers/client tools are likely to include the words "_OLE DB_" or "_ODBC_", and/or "_Client Tools_").

If you are getting the "Could not find installable ISAM" message, and the above did not help, further information can be found here.


Up to list of errors       Go to Database Development FAQs

----------


## si_the_geek

*"Syntax error ..."* 
*"No value given for one or more required parameters."*
*"Too few parameters. Expected ..."*
_What it means:_For one reason or another, the syntax of your SQL statement is not valid (even if it looks fine!).

_How to solve it:_There are a vast amount of potential causes, but there are several we see regularly:
If you are using an SQL statement with an ADO recordset, make sure that the final parameter for the Open method is adCmdText (rather than adCmdTable , which is to specify that you are _not_ using an SQL statement!).
Check that any values you specified are delimited correctly for the data type _(see this FAQ article for the correct methods)_.
Check that these values are actually valid, especially if you are getting any values from the user. For example, ensure that the value for a numeric field contains a number, and that for string data you are dealing with the ' character (_see this FAQ article for an explanation_).
Check that the rest of the syntax is ok (_if you aren't sure, see the tutorials in the SQL section of our Database FAQ's_)
Even if you don't think it is an issue, check that your table/view/field names are valid:
Check carefully that you have spelt the names correctly (exactly the same as they appear in the database).
If a name contains a space or other non-alphanumeric character (such as %) it needs to be enclosed in square brackets within any SQL statements, eg:  
".. FROM [table 1] …"

Ideally you should change the table/field name so that it does not contain these characters, as issues are likely arise in any program that works with it.
If the name is a reserved word (_varies by database system, but generally includes things like Data, Name, Group, Date, Day, Month, Hour, … full lists available here_) then you have bigger problems - every reserved word has some kind of special meaning (many being functions that return a value), so using the same name for a field/table can give unpredictable and/or dangerous results.

Unless you have a very good reason not to, change the name (note that "_I don’t want to_" is a terrible reason!).  

It is possible to use square brackets as above, but this will not cover all situations, eg: in some SQL statements the function will be valid (so if you forget the brackets you will get/edit/delete the wrong data), and it will not 'correct' any other software you use to work with the database.

Up to list of errors       Go to Database Development FAQs

----------


## si_the_geek

*".. Type mismatch .."*
_What it means:_This is basically the same as the error you get in VB: you are trying to use the wrong data type (eg: you are writing a string into an Integer or Date field).

_How to solve it:_You are either accidentally using the wrong field (_check your code/SQL_), have given the field the wrong data type (_check the table design_), or you are using the wrong method/format for putting the value into the field.

If you are putting values into SQL statements, check that you have entered the values in the right way for the data type of the field _(see this FAQ article for the correct methods)_.


Up to list of errors       Go to Database Development FAQs

----------


## si_the_geek

*"String or Binary data would be truncated"* 
*"The field is too small to accept the amount of data..."*
_What it means:_You are attempting to put more data into a field than it can hold.  For example, this would happen if you try to put the text "_Hello_" into a field which is set to only allow 4 characters.

_How to solve it:_First of all, check that you haven't accidentally put values into the wrong fields (especially if you are using an Insert statement).

If the values are going to the right fields - do you actually want to store that much data?If so, increase the size of the field in the table design.If not, you need to check the length of it before trying to insert it into the database, and only enter it if the length is valid.

Up to list of errors       Go to Database Development FAQs

----------


## si_the_geek

*"Item cannot be found in the collection corresponding to the requested name or ordinal"
"Item not found in this collection"*
_What it means:_The field you specified does not exist in the data you are working with.  

_How to solve it:_There are a few potential causes, so check:
Have you mis-spelt the field name?  (it's easily done!)Have you got a field with that name in your database table?Are you getting the data from the correct table?If using a Select statement, have you specified the fields to return, but missed that one?If performing any kind of Join in your query, does that field name exist in more than one of the tables?
_(if so the name in the recordset is likely to be automatically changed for you, so use an Alias for the field in your query and code)._

Up to list of errors      Go to Database Development FAQs

----------


## si_the_geek

*"Either BOF or EOF is True..."*
_What it means:_You have tried to work with a record (eg: reading or writing a value), but there is no record to work with.

_How to solve it:_For one reason or another there is no current record, and what you are doing needs one.  

This error most often happens because of one of the following:
You have just opened the recordset, and tried to use the values - but did not check if there are any records first.  You can do this by checking the BOF and EOF properties of the recordset, eg:

VB Code:
objRs.Open ...If objRs.BOF and objRs.EOF Then  MsgBox "no records returned!"Else  'use valuesEnd If
You performed a .MoveNext when .EOF was true, or .MovePrev when .BOF was true, or any kind of Move when both were true.  Whichever it was, what you did is not recommended - you should check for .EOF/.BOF first, and only move if appropriate.
You have just performed a .Delete on a record.  Depending on where the record is in the recordset, there may not be a "current record" afterwards.. you may be at BOF or EOF (or both if there are no records left in the recordset).

After deleting a record you should check the state of BOF and EOF, if both are true then you can no longer read/edit/delete records until more have been added.  If either BOF or EOF are true, move to an appropriate record (perhaps .MoveFirst for BOF).

Up to list of errors       Go to Database Development FAQs

----------


## si_the_geek

*"Operation is not allowed when the object is closed."*
*"Operation is not allowed when the object is open."*
*"The connection cannot be used to perform this operation. It is either closed or invalid in this context."*
_What it means:_You tried to do something that is not appropriate for the current state (_either Open or Closed_) of the object (_eg: Recordset/Connection_).

Certain operations on database object variables (such as MoveFirst on a RecordSet object) can only be done when the object is in a particular state (for MoveFirst, the RecordSet must be Open).

_How to solve it:_As you are getting one of these errors, you are unlkely to be aware of the following... whatever your situation, you should *always* close Recordsets and Connections when you have finished with them - otherwise you can waste large amounts of memory, and you also risk database corruption!  The code to properly close Recordsets/Connections is like this:

VB Code:
rs.Close   'close the recordset, and release the memory  Set rs = Nothing    cn.Close   'close the connection, and release the memory  Set cn = Nothing
Right then, on to the solutions!   If you get the "not allowed when .. closed" message, you need to Open the object (eg: _rs_.Open ...) before running the line of code that gave you the error.

For "not allowed when .. open", you need to Close the object (eg: _rs_.Close) before running the line of code that gave you the error.  For example, you need to Close a Recordset before you can Open it again.

One issue tho is that you cannot Close a Recordset/Connection unless it is open.  If it is possible in your program that the object will not have been opened (or already have been closed), you need to check that it is open before attempting to close it, eg:

VB Code:
'this method can be used for connections and recordsets  If (rs.State And adStateOpen) = adStateOpen Then rs.Close
If you are unsure that the object has even been Set, you will also need to check that, eg:
VB Code:
If Not rs Is Nothing Then        If (rs.State And adStateOpen) = adStateOpen Then rs.Close  Else    'if you are about to Open you need to also Set the object, eg:    Set rs = New ADODB.Recordset  End If
Note that despite other advice you may see on the forums, just running the Set on its own is not a valid method.  While it _appears_ to work, it does not actually close the existing Recordset/Connection - all it does is create another one, and leave the previous one in memory.  It avoids the error messages, but in a very dubious way!


Up to list of errors       Go to Database Development FAQs

----------


## si_the_geek

*"Unrecognized database format."*
_What it means:_First of all, it _probably_ means that you are using DAO (which includes the standard "Data Control", and "Visual Data Manager") to connect to the database.. this is seriously out-of-date (and is unsupported), so you should not be using it at all.  Microsoft said something similar in the help for VB6, and that was back in 1998!

What the actual error means is that the database cannot be read - either because it is a 'modern' database format, or because the database is corrupted.

_How to solve it:_If you are using a Data Control (even the ADO one), you shouldn't be - see this FAQ article for an explanation, and an example of a well supported alternative (ADO code) including an example program which looks similar to one you would create with a data control.

If you are using DAO code, you should move on to ADO code (which is still 'current' technology). For an explanation of how to use it, see this tutorial.

If you have already been using this database from your program, the database is likely to be corrupted.  Either do a "Compact & Repair" within Access, or see the Access section of the Database FAQ's for a code version.  If you are using DAO in your program, the above solutions still apply!

Finally, if you are using ADO code, this will happen if you are using an old driver.  Change your connection string to use the provider "Microsoft.Jet.OLEDB.4.0". If you have problems with it, install a service pack for VB (SP 6 is available from the Microsoft web site at the time of writing), and/or MDAC.


Up to list of errors       Go to Database Development FAQs

----------


## si_the_geek

*"Multi-step OLE DB operation generated errors. ..."*
_What it means:_The error message simply means that one or more errors happened... how useful!  :Roll Eyes (Sarcastic): 

_How to solve it:_If this occurred when opening a connection, your connection details (or software) are likely to be wrong – so check that they are correct, see above for more info.

The actual errors will be listed somewhere, most likely in object variables that you are using to work with the database.  For ADODB code, you can check what the errors were by looking at the Errors collection of the connection object (eg: _objConn_.Errors) by either adding it as a Watch value in the VB editor, or by iterating the collection in code, eg:

VB Code:
Dim vErr as Variant    For Each vErr In objConn.Errors  'change to the name of your connection object    Debug.Print "ADO error - " & vErr.Number & ": " & vErr.Description  Next vErr
Once you know what the actual errors are (they may be ones listed on this article), you can work on fixing them appropriately.


Up to list of errors       Go to Database Development FAQs

----------

