views:

37

answers:

3

I have migrated a set of SQL 2000 databases to SQL 2008. Most is working well, however I have some stored procedures that scheduled and run by SQL Server Agent jobs that are giving me troubles. Many of the scheduled stored procedures work, but the stored procs that access a database other than the default databases are failing with the following message:

Executed as user: XYZ\YadaYada. The server principal: "XYZ\YadaYada" is not able to access the database "MyOtherDatabaseOnSameServer" under the current security context. [SQL STATE 08004](Error 619) The step failed.

Obviously, I changed the names to protect the guilty.

The account is a user in all of the relavent databases and is a memeber of db_owner, db_datareader, and db_datawriter.

When I run these same procedures from a query window in SMS using the same accounts (I have tried many) they work fine.

What am I missing?

A: 

things you might take a look at:

  • who is the owner of the job?
  • under which user is the sql-agent user running?
Sander
Owner of the job is dbo. Account for SQL Agent is was Network Services, but I changed it to the Domain Admin to see if that would help. It did not.Thanks
Jim Reineri
A: 

This looks like the cross-database ownership chaining issue.

Check that:

  • the SQL server allows cross-database ownership chaining
  • each database involved has cross-database ownership chaining enabled.
  • User XYZ\YadaYada is a registered user of MyOtherDatabaseOnSameServer.
  • The owner of the stored procedures is the same as the owner of the objects held in MyOtherDatabaseOnSameServer.

Hope that helps.

Neil Moss
Owner of all object and owner of stored proc is dbo XYZ\YadaYada is registered user of db I did think of the cross-database ownership chaining and set the option on the server. Did not know about option on each db. When I went to set the option on DB it is grayed out and not settable. Trying to figure out why. This seems like a possible source of problem. Although, I do not understand why it would work ok from SMS query window. Think you for the input, I will keep plugging away at it.
Jim Reineri
You may need to issue the RECONFIGURE statement to have the server pick up the configuration change. Try: sp_configure 'cross db ownership chaining', 1; GO RECONFIGURE; GO If the db-level options are still grayed out, try restarting the sql instance (if you are allowed)
Neil Moss
A: 

When you migrated the users, did you set up the users again or simply take what they had from the restore / attach operation?

You might need to run exec sp_change_users_login 'Auto_Fix', '<username>' on the database(s) in question where <username> is the actual name of the user.

Chris Lively
The account and users that I am using were added after the migration. I did try anyway, but no joy. Thanks for the input.
Jim Reineri