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