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

A

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

Robson Siqueira

Adrien,

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:

SELECT * FROM TEST.dbo.TABLE1

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

Does it work now?
 
A

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 !

A.R.
 

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

Top