Visual Basic Q&A

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries for April, 2010

PRB: Error Assigning Non-Opened Recordset to ADODC

Symptoms
When you attempt to set an ActiveX Data Objects (ADO) Data Control’sRecordset object to a previously dimensioned ADO Recordset the followingerror is returned:

Run-time error ‘3704′:
The operation requested by the application is not allowed if the objectis closed.
Resolution
This error occurs when the recordset has not been opened yet.

PRB: Error “Unrecognized Database Format” When You Upgrade to Access 2000 or 2002

Symptoms
If you try to gain access to an Access 2000 or Access 2002 database, you may receive one of the following errors within your Visual Basic program.
If you are using Microsoft ActiveX Data Objects (ADO) (or the ADO Data Control), you receive the following error message:

Run-time error -2147467259 Unrecognized Database Format XXXIf you are using Data Access Objects (DAO) (or the DAO generic Data Control), you receive the following error message:

Run-time error 3343 Unrecognized Database Format XXX
Resolution
Access 2000 and Access 2002 use the Jet 4.0 engine, which creates Jet 4.0 format database files. Jet 3.5 components do not recognize such a format.If you are using ADO, you get error -2147467259 when you try to connect to your Access 2000 or 2002 database through the Microsoft.Jet.OLEDB.3.51 provider.If you are using DAO, you get error 3343 when you use the Microsoft DAO 3.51 Object Library.The DAO generic Data Control does not work against Access 2000 or 2002 databases and always generates error 3343 unless it is used as instructed in the “Resolution” section of this article. This occurs because this control is based on Jet 3.51 and only recognizes Jet 3.51 (or before) database formats.

PRB: Error “Syntax Error Near ‘Tablename’” on Recordset Update

Symptoms
With SQL Server’s quoted_identifier option set to Off, you may receive the following error:

Run-time error ‘-2147217900 (80040e14)’:
Line 1: Syntax error near ‘tablename’ This error occurs when you are using client-side cursors with the Microsoft OLE DB Provider for SQL Server (SQLOLEDB). The error occurs on an ActiveX Data Objects (ADO) recordset’s Update method and may occur on an AddNew method.
Resolution
With ADO client-side cursors, when you invoke an ADO recordset’s AddNew or Update method, the OLE DB Provider prepares a SQL statement to send to SQL Server.
The Microsoft OLE DB Provider for SQL Server automatically quotes identifiers on an ADO recordset’s Update method and may quote identifiers on an AddNew method. Identifiers include table names and field names.
For example, updating the Titles table in the Pubs database with the following code:

MyADORecordet.Update The preceding would be prepared similar to the following:

UPDATE “titles” SET “title”=’Hello World’ WHERE “title_id”=’3′ Note that the table name is in quotes, “titles”, and that each field name is in quotes, “title”, “title_id”, and so on.
If SQL Server’s Quoted_Identifier option is set to Off, SQL Server will not recognize table names and field names enclosed in quotes.
The error “Syntax error near ‘tablename’” occurs.

PRB: Error “String Literal Too Long” using Update or Insert on Oracle Table

Symptoms
When using the “Microsoft OLE DB Provider for Oracle” to Execute an action query (Update or Insert) on a connection opened to an Oracle 7 or 8 server and a table that has LONG datatype field, you might receive the following error message:

ORA-01704: String literal too long If using the “Microsoft OLE DB Provider for ODBC Drivers,” the error message might look like:

[Microsoft][ODBC driver for Oracle][Oracle] ORA-01704: String literal too long.
Resolution
There is an Oracle limitation of 2000 characters for literal strings on all flavors of Oracle 7 and 4000 characters on Oracle 8.

PRB: Dynaset, Snapshot, and Table Objects No Longer Available

Symptoms
If you try to dimension a Dynaset, Snapshot, or Table object variable andusing DAO 3.0 (Visual Basic version 4.0 data access objects), you willreceive this runtime error:

User-defined type not defined.If you replace the Dynaset, Snapshot, or Table object with the Object orRecordSet type and use methods such as CreateDynaset, CreateSnapshot, orOpenTable that are tied to the Dynaset, Snapshot, or Table types, you willreceive this error:

Feature not available.
Resolution
Visual Basic version 4.0 has replaced the older Dynaset, Snapshot, andTable objects with a single RecordSet object. This object can take on theattributes of any of the older three making it much more powerful andflexible.

PRB: DCOMCNFG Displays One Class Name For Each ActiveX Server

Symptoms
When using the Distributed Component Object Model (DCOM) ConfigurationUtility (Dcomcnfg.exe), only one class for each ActiveX server appears inthe list of applications. This occurs even though an ActiveX server maycontain several classes, each of which is functioning correctly.
Resolution
DCOM provides server level security. All objects within a server share thesame security settings. Therefore, Dcomcnfg.exe only lists the first object(class) for each ActiveX server registered.