472,958 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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.").

<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
2 16675
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: jason | last post by:
Hi Ray...a while ago you explained an elegant solution to enable me to CREATE and EDIT existing tables and queries inside my online access 2000 database.... could you provide refresher links on...
2
by: Dave Moore | last post by:
Hi, I want to use CSS to define the font size in every cell of a table. This avoids needing to define the font size in every <TD> tag using the normal multiple HTML <FONT SIZE="2"> notation....
1
by: Ed Bacon | last post by:
I am trying to produce a generic "audit report" for various transactions in our application. Each transaction type defines a document (and has an associated schema). When a transaction leads to a...
6
by: Marcel Hug | last post by:
Hi all ! I have a table in my database, which has 3 attributes. IDFailureControl, ControlDate and ControlVersion. In the following function I test, if the date of today allready exists. Then I...
2
by: weird0 | last post by:
I am testing a webservice locally that connects to BankingDb and check the function public bool CheckPincode(string Pincode) { SqlConnection sqlConnection1 =new...
0
by: sphinney | last post by:
I have a complex Access 2002 database with multimple tables, queries, forms, and reports. The database is used by miltiple users that have one of four different levels of security. The databae uses...
0
by: Icemokka | last post by:
Hi all, We have 2 databases that are not connected to each other directly. Changes to either databases can only be done on one side. Those 2 databases are of the type MSAccess or MSSQL but with...
3
oll3i
by: oll3i | last post by:
package ejb; import javax.ejb.EJBObject; import java.rmi.RemoteException; import java.sql.Connection; import java.util.Map; public interface InterfaceRemote extends EJBObject { public Map...
5
by: matt | last post by:
This is a strange one but I've been stuck on it for days. Any help appreciated. THE PLAN: I've a database that I use a script to grab all the entries for a particular field. I then want to...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.