473,322 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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");
}
Aug 21 '08 #1
4 3326
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
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
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
Got it!
Aug 26 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: rockie12 | last post by:
I have a db that has a table x in it called data1 I have a program that does to things, updates values in the data1 table and also inserts new rows into this table. The update existing values...
8
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web...
1
by: Frank Py | last post by:
I'm getting the following error when trying an example app: Invalid object name 'Products'. Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'Products'. Line 22:...
3
by: Mr.KisS | last post by:
Hello all, I'm working with : WinXP PRO SP1, MS SQL 2005 Express, Visual Web Dev 2005 Express. I have an aspx page which must execute a stored procedure : ______________ try {...
2
by: Jerry Nelson | last post by:
I get the following error: WGA_Update is a view not a Table Invalid object name 'WGA_Update'. Description: An unhandled exception occurred during the execution of the current web request....
5
by: lds | last post by:
I am getting the following error: The "SendUsing" configuration value is invalid. Description: An unhandled exception occurred during the execution of the current web request. Please review the...
9
by: MR | last post by:
I get the following Exception "The data at the root level is invalid. Line 1, position 642" whenever I try to deserialize an incoming SOAP message. The incoming message is formed well and its...
3
by: Anders Jansson | last post by:
Hi all. I have 2 problems when I try to open and convert an ASP.NET VS 2003 web-applikation in VS 2005. In VS 2003 I have no problems at all! First: One subfolder with will not be converted!...
1
by: Java Guy | last post by:
I'm trying to view a web page. IE tells me there are (Java?) errors on the page. Here they are: Line: 15 Char: 7 Error: Wrong number of arguments or invalid propert assignment Code: 0 URL:...
1
by: samarthkumar84 | last post by:
Hi I had used following code for sending e-mail but facing this problem. I want to send this e-mail in ASP.NET using VB.NET code. I am attaching both code an output. CODE Imports...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.