Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Invalid object name

Reply
 
Old 08-21-2008   #1 (permalink)
Curious


 
 

Invalid object name

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");
}

My System SpecsSystem Spec
Old 08-21-2008   #2 (permalink)
rhaazy


 
 

Re: Invalid object name

On Aug 21, 10:58 am, Curious <fir5tsi...@xxxxxx> wrote:
Quote:

> 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);
My System SpecsSystem Spec
Old 08-21-2008   #3 (permalink)
Curious


 
 

Re: Invalid object name

On Aug 21, 3:20*pm, rhaazy <rha...@xxxxxx> wrote:
Quote:

> On Aug 21, 10:58 am, Curious <fir5tsi...@xxxxxx> wrote:
>
>
>
>
>
Quote:

> > 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'".
>
Quote:

> > 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.
>
Quote:

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

> > * * * *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);
>
Quote:

> > * * * * * * 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.
My System SpecsSystem Spec
Old 08-22-2008   #4 (permalink)
rhaazy


 
 

Re: Invalid object name

On Aug 21, 5:15*pm, Curious <fir5tsi...@xxxxxx> wrote:
Quote:

> On Aug 21, 3:20*pm, rhaazy <rha...@xxxxxx> wrote:
>
>
>
>
>
Quote:

> > On Aug 21, 10:58 am, Curious <fir5tsi...@xxxxxx> wrote:
>
Quote:
Quote:

> > > 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'".
>
Quote:
Quote:

> > > 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.
>
Quote:
Quote:

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

> > > * * * *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);
>
Quote:
Quote:

> > > * * * * * * try
> > > * * * * * * {
> > > * * * * * * * * objCmd.ExecuteNonQuery();
> > > * * * * * * }
> > > * * * * * * catch (System.Exception e)
> > > * * * * * * {
> > > * * * * * * * * Console.WriteLine(e.Message);
> > > * * * * * * }
> > > * * * * * * Console.WriteLine("Records selected");
> > > * * * * }
>
Quote:

> > 'db_dynamic_trading.dbo.TrdRpt_broker_list'
>
Quote:

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

> > 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.
>
Quote:

> > 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 -
>
Quote:

> > - 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 " +
Quote:
Quote:
Quote:

> > > "FROM
> > > dbo.TrdRpt_broker_list " +
> > > "WHERE symbol_requested LIKE '%SCC%'";
My System SpecsSystem Spec
Old 08-26-2008   #5 (permalink)
Curious


 
 

Re: Invalid object name

Got it!
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Inherit from usercontrol - Object not set to instance of an object .NET General
datalist -- Object reference not set to an instance of an object. .NET General
The binary form of an ACE object is invalid PowerShell
Testing object arrays using Compare-Object and -contains PowerShell
Adding canonical aliases for Compare-Object, Measure-Object, New-Object PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46