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 Tagged ‘dataadapter’

“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.

BUG: The DataAdapter Wizard generates an InsertCommand property that includes timestamp columns

Symptoms
When you have a timestamp column in the query of the DataAdapter Wizard, the timestamp column is included in the InsertCommand property of the DataAdapter object, and you receive the following error message:

System.Data.SqlClient.SqlException: Cannot insert a non-null value into a timestamp column. Use INSERT with a column list or with a default of NULL for the timestamp column.”The DataAdapter Wizard uses OLE DB or Microsoft SQL Client .NET Data Providers. Although the timestamp columns are read-only columns in the table, you notice that the CommandText property in the InsertCommand property is the following:

INSERT INTO Tablename(column, timestampcolumn) VALUES (@column, @timestampcolumn); SELECT column, timestampcolumn FROM Tablename
Resolution
timestamp columns are read-only columns of the table, and the values in each row of the timestamp column are unique. When the DataAdapter object connects to the Database through the Data Providers to run a set of commands, the columns in a table that cannot be updated or be inserted are marked as read-only by the Data Providers and are not included in the InsertCommand property or the UpdateCommand property of the DataAdapter object. But the timestamp columns are not marked as read-only by the .NET Data Providers in the DataAdapter object. Therefore, the InsertCommand property includes the timestamp columns.

“Type ‘DataSetName’ is not defined” error message when you build the project

Symptoms
When you create a DataSet during design time by using the Generate DataSet option of a DataAdapter, an instance of the DataSet is automatically created on the form. When you modify the name of the DataSet in the Properties window, save the project, and then try to open the form, you may receive the following error message on the form:

An error occurred while loading the document. Fix the error, and then try loading the document again. The error message follows:
Unspecified errorWhen you build your project, you may receive the following error message:

Type ‘ApplicationName.OldDataSetName’ is not defined.
Resolution
The problem occurs because when the DataSet name is changed in the DataSet schema file (.xsd), Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET does not modify the DataSet name in the InitializeComponent of the form where the DataSet is initialized.