You should first verify your connection string:
- Ensure it is connecting to the SQL Server instance you think it is.
- Ensure that it is establishing the database context for the connection in the database you think that it is.
- Ensure that it is connecting with the credentials you think that it is.
- Ensure that those credentials map to the SQL Server user you think that it should
- That that SQL Server user has the default schema you think it does and that it has appropriate rights granted in the database.
Almost certainly, your problem derives from one or more of the issues listed above.
If your database context for the connection is in a different database than you think, you probably won't find the objects you're looking for.
If your object references are not schema-qualified, you may have a problem resolving object references. Object references in your SQL queries should always, at the very least, be schema-qualified. Instead of saying
select * from tblEmployees
you should be saying
select * from dbo.tblEmployees
where dbo is the schema that owns the object. Any object references that are not schema-qualified are looked up at run time in the following order
- First, the current user's default schema is probed for an object of the desired name.
- If that fails, the
dbo schema ('data base owner') is probed for an object of the desired name.
For stored procedures, the lookup is more complex:
- Probe the current user's default schema in the current database.
- Probe the 'dbo' schema in the current database.
If the stored procedure name begins with 'sp_',
- Probe the current user's default schema in the 'master' database.
- Probe the 'dbo' schema in the 'master' database.
If the object in question belongs to another schema, it will not be found unless qualified by the owner schema.
Due to the multiple lookup issue, lack of schema-qualification can prevent execution plan caching, meaning that the query plan has to be recompiled on every execution of a query. Needless to say, this has...sub-optimal effects on performance.
Further, you may get...interesting...results if your database user is 'dev' and the dev in question, 6 months back, created a table or other object named 'dev.foo' during development. Now you're live in production and connecting as user 'dev'. Executing select * from foo will bind to dev.foo in preference to the actual production table that the DBA created, 'dbo.foo'. Your users will be wondering why their data is missing or you'll be ripping your hair out wondering why the app is whining about missing columns when they appear to be all there when you look at it via the SQL Management Studio.
INSERT INTO, it says the same error. But I can add records manually when I open the table...