First check the connection string:
- Make sure it connects to the instance of SQL Server that you think is.
- Make sure that it sets the database context for the connection to the database that you think is.
- Make sure it connects to the credentials that you think are.
- Ensure that these credentials are mapped to a SQL Server user who you think should
- That the SQL Server user has a default schema, which, in your opinion, has and has the corresponding rights granted in the database.
Almost certainly, your problem is related to one or more of the problems listed above.
If your connection database context is in a different database than you think, you probably won't find the objects you are looking for.
If your links to objects do not meet the criteria of the scheme, there may be a problem with resolving links to objects. References to objects in your SQL queries should always at least be schematically qualified. Instead of talking
select * from tblEmployees
you have to say
select * from dbo.tblEmployees
where dbo is the schema that owns the object. Any references to objects that do not meet the criteria of the schema are checked at runtime in the following order.
- First, for the object with the desired name, the current user default scheme is examined.
- If this fails, the
dbo ("database owner") is examined for the object with the desired name.
For stored procedures, the search is more complicated:
- In the current database, program the default user schema.
- Pull the dbo schema in the current database.
If the name of the stored procedure begins with 'sp_',
- Set the default user schema in the "master" database.
- Try the "dbo" schema in the "master" database.
If the object in question belongs to another scheme, it will not be found unless it is specified according to the ownerβs scheme.
Due to the multiple search problem, lack of qualification of the schema can prevent caching of the execution plan, which means that the query plan must be recompiled every time the query is executed. Needless to say, this is ... a suboptimal performance impact.
In addition, you can get ... interesting ... results if your database user "dev" and the corresponding developer, 6 months ago, created a table or other object named "dev.foo" during development. Now you live in production and connect as a custom "dev". Executing select * from foo will bind to dev.foo according to the actual production table created by the DBA, "dbo.foo". Your users will be wondering why their data is missing, or you will rip your hair off, wondering why the application whines around the missing columns when they seem to be all there when you look at it through SQL Management Studio.