views:

125

answers:

2

I recently did an import of database from a sql server 2000 database to a sql server 2005 database. I've gone through and setup what I thought were the same login credentials and owner permissions that I had previously setup in my old database.

All of the code base I'm working has stored procedures listed simply by stored procedure name.

In order to make sure I have the proper logins created, I am logging into the SQL Server Management studio with the connection information my application is using (i.e. using the username "licensemgr" and it's associated password). I can see all the tables, stored procedures, etc... in my database when I log in with combination. When I try to run a stored procedure, Sql Server Management Studio uses the following syntax to execute it:

EXEC: @return_value = [licensemgr].[Stored_Procedure_Name]

and it executes without error.

If I try to remove the [licensemgr]. from before the [Stored_Procedure_Name], however I get the error "Cannot find stored procedure: Stored_Procedure_Name". This is the same error I get when running my application off this database. I changed one stored procedure call in my application to have "licensemgr." in front of the stored procedure name and that seemed to correct the problem, however, I don't want to do that for each and every stored procedure call in my application. I am therefore wondering what type of setup / permissions type issue I might be missing in my SQL Server instance so that even when I'm logged into the database as licensemgr, I cannot see the stored procedure which is in the schema "licensemgr".

+1  A: 

When you created your user, did you specify DEFAULT_SCHEMA?

CREATE USER ... WITH DEFAULT_SCHEMA = "licensemgr"

If not, you may need to use ALTER USER to fix this for your user in the new system.

Harold L
I used SQL Server Management Studio to create the user and I set the default schema to licensemgr. So I think I'm good here.
Kivus
+1  A: 

In SQL server 2000 the [licensemgr] referred to the owner of the table. So when you are logged in as [licensemgr] you do not need the prefix.

In SQL Server 2005 this has been changed to the schema, therefore it must be specified. See:

http://msdn.microsoft.com/en-us/library/ms190387.aspx

EDIT

There are two things that you need to watch out for:

  • If the user is in the sysadmin role, he will always default to the dbo schema, therefore you need to prefix
  • If your user needs to run code that is in different schemas you will need to prefix

If none of the two above it should work by setting the default schema for the user

Shiraz Bhaiji
So just to clarify, you're saying (and the article is saying if I read it correctly) that in SQL Server 2005, you have to specify schema name for each stored procedure because of the separation of ownership from schema names? I don't mind modifying all my code if that's the way things need to be, I just want to make sure I'm understanding you correctly.
Kivus