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


Adrien Reboisson

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
(The original message, in French, is "Nom d'objet '<TableName>' non

<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é */

inGridView.AutoGenerateColumns = true;


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

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

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

Any hint greatly appreciated !

Best regards,




Robson Siqueira


This probably may be happening because of your database connection, which
probably is not pointing to the right DB. Try this:

SELECT * FROM databasename.owner.yourtablename

using the information you gave us:


Since you don't list here the code to connect to the database, verify the
database connection.

Does it work now?



Adrien Reboisson

Robson Siqueira a écrit :
SELECT * FROM databasename.owner.yourtablename

Does it work now?

Yes. Thank you very much Robson, you saved my week end ;-)

Cheers from France !


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question