The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MS SQL Development
|
Invalid object name
Discuss Invalid object name in the MS SQL Development forum on Dev Shed. Invalid object name MS SQL Development forum discussing administration, MS SQL queries, and other MS SQL-related topics. SQL Server is Microsoft's enterprise database engine.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 9th, 2012, 04:03 AM
|
 |
המבין יבין
|
|
Join Date: Jul 2001
Location: Haifa
|
|
|
Invalid object name
I have an SQL Express file with a single table People. People has six or seven columns, but no rows. The database is a resource in my Visual Studio 2010 Express project. I am trying to connect with this code:
Code:
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS; AttachDbFilename=C:\\someLocation\\someDatabase.mdf; Integrated Security=True; User Instance=True ");
conn.Open();
SqlCommand cmd = new SqlCommand(@"select * from People;", conn);
However, I am getting the following error:
Code:
Invalid object name 'People'.
Based on some casual googling I tried to precede the table name with dbo (dbo.People) but that did not resolve the issue. What might I be doing wrong?
Thanks.
|

February 9th, 2012, 07:17 AM
|
 |
Contributing User
|
|
|
|
|
Looks like you don't have a table named [People].
Verify that the table does exist and is spelled correctly.
|

February 9th, 2012, 07:55 AM
|
 |
המבין יבין
|
|
Join Date: Jul 2001
Location: Haifa
|
|
|
Thank you. Actually, there is most certainly a table named People, spelling verified by copy-and-paste.
|

February 13th, 2012, 04:56 AM
|
 |
המבין יבין
|
|
Join Date: Jul 2001
Location: Haifa
|
|
Quote: | Originally Posted by dotancohen Thank you. Actually, there is most certainly a table named People, spelling verified by copy-and-paste. |
It can be seen here that the table does exist, and is populated with data:

|

February 21st, 2012, 09:48 AM
|
|
Registered User
|
|
Join Date: Feb 2012
Location: Kansas City
|
|
|
Most of the time this is because you are looking in the wrong database.
Are you positive your pointing to the correct database?
|

February 21st, 2012, 11:58 AM
|
 |
המבין יבין
|
|
Join Date: Jul 2001
Location: Haifa
|
|
|
I want to say that I'm sure, but I'm not! I now see that since my project is on a network drive Visual Studio is creating the database inside the project, then silently making a copy in my profile folder (I'm not running as Admin) and using that one. So the database created in the project is not the same database that is shown in the Database Explorer.
What a mess! At least I've found the issue. Thanks.
|

February 21st, 2012, 12:03 PM
|
|
Registered User
|
|
Join Date: Feb 2012
Location: Kansas City
|
|
|
Yeah no problem. It's very common.
I don't remember how many times I did that to myself in the management studio. I had master db selected but was trying to query tables from another database.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|