MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 9th, 2012, 04:03 AM
dotancohen's Avatar
dotancohen dotancohen is offline
המבין יבין
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2001
Location: Haifa
Posts: 2,084 dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 17 h 52 m
Reputation Power: 1484
Send a message via ICQ to dotancohen Send a message via AIM to dotancohen Send a message via MSN to dotancohen Send a message via Yahoo to dotancohen
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.
__________________
. . . What is Firefox?
. . . . . . What is Linux?
. . . . . . . . . . . What is Love?

Reply With Quote
  #2  
Old February 9th, 2012, 07:17 AM
Vomster's Avatar
Vomster Vomster is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2005
Posts: 724 Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 2 h 26 m 31 sec
Reputation Power: 290
Looks like you don't have a table named [People].

Verify that the table does exist and is spelled correctly.

Reply With Quote
  #3  
Old February 9th, 2012, 07:55 AM
dotancohen's Avatar
dotancohen dotancohen is offline
המבין יבין
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2001
Location: Haifa
Posts: 2,084 dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 17 h 52 m
Reputation Power: 1484
Send a message via ICQ to dotancohen Send a message via AIM to dotancohen Send a message via MSN to dotancohen Send a message via Yahoo to dotancohen
Thank you. Actually, there is most certainly a table named People, spelling verified by copy-and-paste.

Reply With Quote
  #4  
Old February 13th, 2012, 04:56 AM
dotancohen's Avatar
dotancohen dotancohen is offline
המבין יבין
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2001
Location: Haifa
Posts: 2,084 dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 17 h 52 m
Reputation Power: 1484
Send a message via ICQ to dotancohen Send a message via AIM to dotancohen Send a message via MSN to dotancohen Send a message via Yahoo to dotancohen
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:
Attached Images
File Type: png visual-studio.png (78.0 KB, 24 views)

Reply With Quote
  #5  
Old February 21st, 2012, 09:48 AM
DeveloperBase DeveloperBase is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Location: Kansas City
Posts: 12 DeveloperBase User rank is Sergeant (500 - 2000 Reputation Level)DeveloperBase User rank is Sergeant (500 - 2000 Reputation Level)DeveloperBase User rank is Sergeant (500 - 2000 Reputation Level)DeveloperBase User rank is Sergeant (500 - 2000 Reputation Level)DeveloperBase User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 h 1 m
Reputation Power: 0
Most of the time this is because you are looking in the wrong database.

Are you positive your pointing to the correct database?
Comments on this post
dotancohen agrees!

Reply With Quote
  #6  
Old February 21st, 2012, 11:58 AM
dotancohen's Avatar
dotancohen dotancohen is offline
המבין יבין
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2001
Location: Haifa
Posts: 2,084 dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level)dotancohen User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 17 h 52 m
Reputation Power: 1484
Send a message via ICQ to dotancohen Send a message via AIM to dotancohen Send a message via MSN to dotancohen Send a message via Yahoo to dotancohen
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.

Reply With Quote
  #7  
Old February 21st, 2012, 12:03 PM
DeveloperBase DeveloperBase is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Location: Kansas City
Posts: 12 DeveloperBase User rank is Sergeant (500 - 2000 Reputation Level)DeveloperBase User rank is Sergeant (500 - 2000 Reputation Level)DeveloperBase User rank is Sergeant (500 - 2000 Reputation Level)DeveloperBase User rank is Sergeant (500 - 2000 Reputation Level)DeveloperBase User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 h 1 m
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Invalid object name

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap