![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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"); > } 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 Specs![]() |
| | #3 (permalink) |
| | 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 - 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 Specs![]() |
| | #4 (permalink) |
| | 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 - 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 Specs![]() |
| | #5 (permalink) |
| | Re: Invalid object name Got it! |
My System Specs![]() |
![]() |
| 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 | |||