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 May, 2010

“Connection string is invalid” error message when you preview data or generate a dataset control

Symptoms
If more than one connection exists in Microsoft Visual Studio .NET Server Explorer, and if you cannot see Server Explorer in Visual Studio .NET, you may receive the following error message when you click Fill Dataset to preview the data in the Data Adapter Preview window:

SqlDataAdapterName. The data adapter could not return the data from the data source.
The connection string is invalid.Alternatively, when you right-click DataAdapter and then click Generate Dataset, you may receive the following error message:

Retrieving the schema for SqlDataAdapter1 failed.
The connection string is invalid.
Resolution
Connection Manager manages the Microsoft SQL Server connections in Visual Studio .NET. When you click Fill Dataset or Generate Dataset, a Connection object is built and then added to the Connection Manager list of Connection objects. Connection Manager finds the Connection in its list and then prepares to return the Connection with the display name of the Connection. To return the display name, Connection Manager incorrectly opens Server Explorer and then looks for a connection in Server Explorer. Connection Manager generates an error because the connection does not exist in Server Explorer.

PRB: Improper Installation of MDAC May Return Error Message “Method ‘~’ of Object ‘~’ Failed” at Run Time with ADO Application

Symptoms
When you attempt to run simple ActiveX Data Objects (ADO) code in an application, the following error can occur:

“Method ‘~’ of Object ‘~’ Failed”
Resolution
The most common cause for this error is mismatched DLL files with Microsoft Data Access Components (MDAC).

PRB: GetChunk Corrupts Binary Data on Win98/NT4 SP4

Symptoms
When using the Data Access Objects (DAO), Remote Data Objects (RDO) or the ADO GetChunk method, on a long binary field of a Microsoft Access database, binary data may appear corrupt if the binary information previously stored was read from disk using a String (BSTR) variable instead of a Byte array. The problem occurs under one of the following conditions:
You recently upgraded your computer to Windows 98 or Windows NT version 4.0 SP4. Previously stored data now appears corrupt.
-or-You are using a shared database. The corruption occurs when the binary data was stored by clients running on Windows 95 or Windows NT 4.0 SP3, and then extracted by clients running Windows 98 or Windows NT 4.0 SP4 or vice versa.
Resolution
The problem is that the information stored to the database is mistakenly being converted to Unicode before being stored. The “corruption” occurs when reading the information from disk using the Visual Basic or Visual Basic for Applications Get statement.
By design, the Get statement relies on the data type of the variable to determine how the information should be read into Visual Basic. If you pass a String (BSTR) variable to the function, Visual Basic identifies the information as being a text string, and converts it to Unicode. However, since the data is binary and not text, this conversion corrupts the data before it is ever stored to the database.
Although binary data stored in Unicode format can be “decoded” in some cases, it requires that the Unicode symbol table used to map 1-byte ANSI characters to 2-byte Unicode characters be the same for both the conversion to and the conversion from Unicode. Due to the recent addition of the European Currency symbol, the symbol table for Windows 98 and Windows NT 4.0 SP4 is different from those used previously. These changes will have no effect on text strings, but can effect binary data mistakenly converted to Unicode.

PRB: FileMon Shows That DAO360.dll Fails to Load MSJet49.dll, MSJet48.dll, and Other MSJetxx.dll Files

Symptoms
When you use FileMon or another utility to monitor file activity, if an application uses DAO 3.6x with Jet 4.0, you receive the following error message:

FILE NOT FOUNDfor the following dynamic-link libraries (DLLs):
MSJET49.DLL
MSJET48.DLL
MSJET47.DLL
MSJET46.DLL
MSJET45.DLL
MSJET44.DLL
MSJET43.DLL
MSJET42.DLL
MSJET41.DLLHowever, you also notice that MSJET40.DLL is loaded successfully.
Resolution
This behavior is by design to allow future Jet 4 functionality to be included into DLLs that are named incrementally. For example, a new version of Jet 4 can be implemented in a DLL named MSJET41.DLL. DAO 3.60 then automatically uses the new version of Jet 4, MSJET41.DLL.
Microsoft Development has found that it does not significantly impact DAO 3.60 or Jet 4.0 performance to load these DLLs.

PRB: Explaining “Record is deleted” error accessing ODBC table

Symptoms
Error 3167 “Record is Deleted” is a common error when using the Data AccessObjects (DAO) or a data control to access ODBC tables. This is due to theway that the Microsoft Jet Database Engine manipulates its cursor for therecordset. It is not limited to DAO. Similar errors can be raised by anyengine that maintains a cursor. The ODBC cursor library and serversthemselves can and will raise similar errors. Understanding why and howthese errors are caused requires a knowledge of resultset and cursorbehavior.
Resolution
The “Record is Deleted” error (error 3167) is a byproduct of the Jetengine’s keyset cursor for the dynaset type recordset. A keyset cursor isfixed in membership, but there is nothing stopping another user fromdeleting a row in the underlying table that you have selected in yourkeyset. When you attempt to get the data or update the data in a deletedrow, the “Record is Deleted” error message is generated. Again, thisbehavior is not limited to the Jet engine, but can occur in any keysetcursor.
This is not the only cause of the error. There are several other causesthat are far more subtle and depend on the keyset implementation. Becausethe Jet engine uses a keyset based on a unique index in the underlyingtables, it is possible to get this error if something changes the indexinformation. When the fields that the keyset is built from are changed inthe underlying table for a given record, the Jet engine is not able to findthe record to read or update the data and raises the “Record is Deleted”error. In most cases the Jet engine knows that the indexed fields changedin the underlying table if it made the changes, but the following couldchange the indexed fields without the Jet engine being aware of it:
Other users. Other users may change the values in the indexed fields.When the Jet engine is unable to find that record based on the valuethat it is storing, it raises an error.Triggers. Triggers can change the values in the indexed fields. Sincea trigger changes the values from what the Jet engine thinks it putin there, the cached keyset value and the actual value in the tablediffer. When the Jet engine tries to fetch the record, it will raisean error.Null and Empty String behavior. Many databases automatically changedata if necessary without alerting the Jet engine. For example, if theuser were to add a record where the indexed column was a varchar() andthe user submitted a “” value for that field, SQL Server would changethe “” into a space (” “) and not alert the Jet engine. The Jet enginewould then try to find that record with “”, fail to do so and raise the”Record is Deleted” error.Functions. Many indexed fields are updated with server functions such asGetDate(). These can change the indexed data without the Jet engineknowing it.Indexes on non-standard datatypes or floating point datatypes. Someserver datatypes have no ODBC or Jet engine equivalent datatype. In mostcases, the Recordset is created as read-only, but sometimes it is not.Rounding or conversion errors on the datatypes can cause the error aswell.

PRB: Executing Refresh Method of ADO Data Control Causes Syntax and Method Refresh Errors

Symptoms
When you set the RecordSource property of an ADO Data Control to a different SQL SELECT statement and then try to execute the Refresh method, the following error is returned:

Syntax error in FROM clause.which is followed by:

Run-time error ‘-2147217900(80040e14)’:
Method ‘Refresh’ of object ‘IAdodc’ failedor:

Method ‘Refresh’ of object ‘IAdodc’ failed when attempting to refresh an ADODC after setting the recordsource property to another value.The errors occur if the CommandType property of the ADO Data Control is set to adCmdTable.
Resolution
When the CommandType of the ADO Data Control is set to adCmdTable, “SELECT * From” is automatically prepended to the RecordSource value.
Setting the RecordSource to a table name results in a valid SQL statement, such as SELECT * FROM Tablename.
Setting the RecordSource to a SQL SELECT statement, such as Select * From Tablename, results in a SQL statement ofSelect * From Select * From Tablename, which is an invalid SQL statement.