SqlDataAdapter.Fill() : Invalid object name <TableName>



I'm trying to build a basic DB explorer using C# & Visual Studio 2005. I installed SQL Server 2005 Express, created a blank project, dropped a TreeView, a ListView and a DataGridView : DB objects (Databases, tables, SPs, and so on) are displayed in the tree, table colums definitions in the list and I want to display the selected table content in the DataGridView. So far so good. Currently, I succedded in loading the treeview and the listview but I CAN'T connect the DataGridView with my database in order to make it display a table content !!

The same exception is ALWAYS raised by the Fill() method of a SqlDataAdapter I create to build the view :

sqlAdapter.Fill(dataTable): Unhandled SQL exception: Invalid object name <TableName>
(The original message, in French, is "Nom d'objet '<TableName>' non valide.").

<TableName> can be replaced by every table I have in my server, I checked with a database I created (Database TEST, Table TABLE1) and with system databases like tempdb, master, or msdb) without any success.

I'm puzzled. I tried to prefix the table names by their schema or their parent database name, but the exception is still raised.

Here is my code :


public void fillDataGrid(DataGridView inGridView,
string inSelectCommand)
{
/* Vérifier qu'on est connecté */
checkConnected();

inGridView.AutoGenerateColumns = true;

inGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);

DataTable dataTable = new DataTable();
SqlCommand sqlCommand = new SqlCommand(inSelectCommand, sqlConnection_);

/* Remplir la vue */
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCommand);
sqlAdapter.Fill(dataTable);

inGridView.DataSource = dataTable;

}

"inSelectCommand" can be "SELECT * FROM Table1", "SELECT * FROM TEST.TABLE1" (using the parent DB name), or "SELECT * from dbo.TABLE1" (using the owner's name), for instance; the exception is always raised.

My connection string :
- doesn't provide a startup database since I've to be able to explore them all
- Use "tcp:(local), 1025" or "DOMAIN\USER" to specify my local computer (I'm running XP SP2 with admin rights)
- Use "Integrated Security = True" to use the Windows integrated security.

Any hint greatly appreciated !

Best regards,

A.R.
.



Relevant Pages

  • Re: Enterprise Library and PostgreSQL (Npgsql)
    ... I found the database provider code at ... Catch ex As Exception ... If the connection string is invalid or the database server is ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework)
  • Object reference not set to an instance of an object.
    ... Object reference not set to an instance of an object. ... An unhandled exception occurred during the execution of the ... Dim myJobRequest As New skillsDB.jobRequest ... Session= "The skills database has been updated ...
    (microsoft.public.dotnet.general)
  • Object reference not set to an instance of an object.
    ... ASP.NET that uses web service for SQL Server 2000 DB access. ... Exception Details: System.NullReferenceException: Object reference not ... Dim myJobRequest As New skillsDB.jobRequest ... Session= "The skills database has been updated ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: SqlCeConnection
    ... data from the database using either a DataReader, DataSet, and binding the ... error but the Exception object does not contain a message to display. ... private void CloseConnection() ... SqlCeCommand sqlCommand = null; ...
    (microsoft.public.sqlserver.ce)
  • Re: [ANN] Data Source Name parser (ODBC etc.)
    ... > suggested URL-like strings describing database connections. ... > library for such strings (data source names) is now available at ... raises the exception Syntax_Error. ...
    (comp.lang.ada)