By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,650 Members | 1,871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,650 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.").

<TableNamecan 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(DataGridViewAutoSizeC olumnsMode.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.
Jan 27 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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?

--
Regards,
Robson Siqueira
Enterprise Architect
"Adrien Reboisson" <ad****************************@nospam.comwrote in
message news:uQ**************@TK2MSFTNGP03.phx.gbl...
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.").

<TableNamecan 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(DataGridViewAutoSizeC olumnsMode.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.

Jan 27 '07 #2

P: n/a
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.
Jan 28 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.