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

Invalid object name

P: n/a
I got an exception when executing the SQL statement in my code below.
The error is "Invalid object name
'db_dynamic_trading.dbo.TrdRpt_broker_list'".

I know for a fact that 'db_dynamic_trading.dbo.TrdRpt_broker_list' is
valid, because I can run the same SQL statement in Management Studio
and it works.

Any advice on this? Is there anything wrong with my connection string
(although there is no complaint about the connection string in my
debugger)?
static void Main(string[] args)
{
string sConnectionString = "Integrated
Security=SSPI;Initial Catalog=db_dynamic_trading;Data
Source=PANSQLDEV";
SqlConnection objConn = new
SqlConnection(sConnectionString);
objConn.Open();
string sSQL = "SELECT DISTINCT symbol_requested " +
"FROM
db_dynamic_trading.dbo.TrdRpt_broker_list " +
"WHERE symbol_requested LIKE '%SCC%'";
SqlCommand objCmd = new SqlCommand(sSQL, objConn);

try
{
objCmd.ExecuteNonQuery();
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Records selected");
}
Aug 21 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Aug 21, 10:58 am, Curious <fir5tsi...@yahoo.comwrote:
I got an exception when executing the SQL statement in my code below.
The error is "Invalid object name
'db_dynamic_trading.dbo.TrdRpt_broker_list'".

I know for a fact that 'db_dynamic_trading.dbo.TrdRpt_broker_list' is
valid, because I can run the same SQL statement in Management Studio
and it works.

Any advice on this? Is there anything wrong with my connection string
(although there is no complaint about the connection string in my
debugger)?

static void Main(string[] args)
{
string sConnectionString = "Integrated
Security=SSPI;Initial Catalog=db_dynamic_trading;Data
Source=PANSQLDEV";
SqlConnection objConn = new
SqlConnection(sConnectionString);
objConn.Open();
string sSQL = "SELECT DISTINCT symbol_requested " +
"FROM
db_dynamic_trading.dbo.TrdRpt_broker_list " +
"WHERE symbol_requested LIKE '%SCC%'";
SqlCommand objCmd = new SqlCommand(sSQL, objConn);

try
{
objCmd.ExecuteNonQuery();
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Records selected");
}
'db_dynamic_trading.dbo.TrdRpt_broker_list'

this table name looks funny, are you sure its correct?

also objCmd.ExecuteNonQuery(); is wrong.
Execute NON query is usually used for update or delete commands.
where is the result of your select statement going to be saved? you
need to have some object that will hold the result of your statement.
See below for example.

SqlCommand cmd = new SqlCommand("some SELECT statement here", con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
Aug 21 '08 #2

P: n/a
On Aug 21, 3:20*pm, rhaazy <rha...@gmail.comwrote:
On Aug 21, 10:58 am, Curious <fir5tsi...@yahoo.comwrote:


I got an exception when executing the SQL statement in my code below.
The error is "Invalid object name
'db_dynamic_trading.dbo.TrdRpt_broker_list'".
I know for a fact that 'db_dynamic_trading.dbo.TrdRpt_broker_list' is
valid, because I can run the same SQL statement in Management Studio
and it works.
Any advice on this? Is there anything wrong with my connection string
(although there is no complaint about the connection string in my
debugger)?
* * * *static void Main(string[] args)
* * * * {
* * * * * * string sConnectionString = "Integrated
Security=SSPI;Initial Catalog=db_dynamic_trading;Data
Source=PANSQLDEV";
* * * * * * SqlConnection objConn = new
SqlConnection(sConnectionString);
* * * * * * objConn.Open();
* * * * * * string sSQL = "SELECT DISTINCT symbol_requested " +
* * * * * * * * * * * * * "FROM
db_dynamic_trading.dbo.TrdRpt_broker_list " +
* * * * * * * * * * * * * "WHERE symbol_requested LIKE '%SCC%'";
* * * * * * SqlCommand objCmd = new SqlCommand(sSQL, objConn);
* * * * * * try
* * * * * * {
* * * * * * * * objCmd.ExecuteNonQuery();
* * * * * * }
* * * * * * catch (System.Exception e)
* * * * * * {
* * * * * * * * Console.WriteLine(e.Message);
* * * * * * }
* * * * * * Console.WriteLine("Records selected");
* * * * }

'db_dynamic_trading.dbo.TrdRpt_broker_list'

this table name looks funny, are you sure its correct?

also objCmd.ExecuteNonQuery(); is wrong.
Execute NON query is usually used for update or delete commands.
where is the result of your select statement going to be saved? *you
need to have some object that will hold the result of your statement.
See below for example.

SqlCommand cmd = new SqlCommand("some SELECT statement here", con);
* * * * * * * * cmd.CommandType = CommandType.Text;
* * * * * * * * SqlDataAdapter adp = new SqlDataAdapter(cmd);
* * * * * * * * DataSet ds = new DataSet();
* * * * * * * * adp.Fill(ds);- Hide quoted text -

- Show quoted text -
The table name is 'TrdRpt_broker_list'. However, I must add the
database name plus 'dbo' before it
('db_dynamic_trading.dbo.TrdRpt_broker_list'); otherwise, I'll get an
error about table not found.

I do need to return the records that return from the SELECT statement.
Thanks for the sample code. I'll give it a try.
Aug 21 '08 #3

P: n/a
On Aug 21, 5:15*pm, Curious <fir5tsi...@yahoo.comwrote:
On Aug 21, 3:20*pm, rhaazy <rha...@gmail.comwrote:


On Aug 21, 10:58 am, Curious <fir5tsi...@yahoo.comwrote:
I got an exception when executing the SQL statement in my code below.
The error is "Invalid object name
'db_dynamic_trading.dbo.TrdRpt_broker_list'".
I know for a fact that 'db_dynamic_trading.dbo.TrdRpt_broker_list' is
valid, because I can run the same SQL statement in Management Studio
and it works.
Any advice on this? Is there anything wrong with my connection string
(although there is no complaint about the connection string in my
debugger)?
* * * *static void Main(string[] args)
* * * * {
* * * * * * string sConnectionString = "Integrated
Security=SSPI;Initial Catalog=db_dynamic_trading;Data
Source=PANSQLDEV";
* * * * * * SqlConnection objConn = new
SqlConnection(sConnectionString);
* * * * * * objConn.Open();
* * * * * * string sSQL = "SELECT DISTINCT symbol_requested " +
* * * * * * * * * * * * * "FROM
db_dynamic_trading.dbo.TrdRpt_broker_list " +
* * * * * * * * * * * * * "WHERE symbol_requested LIKE '%SCC%'";
* * * * * * SqlCommand objCmd = new SqlCommand(sSQL, objConn);
* * * * * * try
* * * * * * {
* * * * * * * * objCmd.ExecuteNonQuery();
* * * * * * }
* * * * * * catch (System.Exception e)
* * * * * * {
* * * * * * * * Console.WriteLine(e.Message);
* * * * * * }
* * * * * * Console.WriteLine("Records selected");
* * * * }
'db_dynamic_trading.dbo.TrdRpt_broker_list'
this table name looks funny, are you sure its correct?
also objCmd.ExecuteNonQuery(); is wrong.
Execute NON query is usually used for update or delete commands.
where is the result of your select statement going to be saved? *you
need to have some object that will hold the result of your statement.
See below for example.
SqlCommand cmd = new SqlCommand("some SELECT statement here", con);
* * * * * * * * cmd.CommandType = CommandType.Text;
* * * * * * * * SqlDataAdapter adp = new SqlDataAdapter(cmd);
* * * * * * * * DataSet ds = new DataSet();
* * * * * * * * adp.Fill(ds);- Hide quoted text -
- Show quoted text -

The table name is *'TrdRpt_broker_list'. However, I must add the
database name plus 'dbo' before it
('db_dynamic_trading.dbo.TrdRpt_broker_list'); otherwise, I'll get an
error about table not found.

I do need to return the records that return from the SELECT statement.
Thanks for the sample code. I'll give it a try.- Hide quoted text -

- Show quoted text -
you shouldn't need to include the database name as part of your
object. when you create your connection string the database should be
specified there.

string sSQL = "SELECT DISTINCT symbol_requested " +
"FROM
dbo.TrdRpt_broker_list " +
"WHERE symbol_requested LIKE '%SCC%'";
Aug 22 '08 #4

P: n/a
Got it!
Aug 26 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.