Total Pageviews

Tuesday, October 25, 2011

Renaming SA account in SQL server 2005



For security reason we can change the SA name any name, to do this you can use ALTER LOGIN
t-sql
Syntax : ALTER LOGIN [sa] WITH NAME = [New Name];
Note : Keep in mind that renaming SA account does not change its SID, SA account always have a SID with value 0x01.
Use the below query to check the SID(Security Identifier).

select * from sys.syslogins
out put will be like as mentioned below-



Refer above ,some of the important information you can get like :creation of login date ,recent modification date and Gives what permission he has at the SQL server instance level(I cut the output here).
Now I rename the Login as mentioned below
Use master
ALTER LOGIN [sa] WITH NAME = [Uday];
Once you have executed you can see result as : Command(s) completed successfully(in query window).
To verify see in SSMS or you can use the T-sql


How ever verify the SID –shows same SID



Note ->Do verify yourself about the job owner as well..(automatically the job owner will change but in my case it was not).



EX - I have one job created via Maintenance plan to backup databases and below is the  error in my test server says as mentioned-
Date                25/10/2011 21:41:06
Log                  Job History (backup database)
Step ID                       0
Server              RAKUBERA\SQL2K5
Job Name                    backup database
Step Name                  (Job outcome)
Message
The job failed.  The owner (sa) of job backup database does not have server access.

How ever what happened in my case the job  keep failing as mentioned below even after change the job owner from  sa to Uday

Message
The job failed.  The owner (sa) of job backup database does not have server access.
 So I have tried many ways but still the jobs were failing-


So final option I decided to restart sql server agent(if that didn’t work plan to recycle SQL server services to see whether it will resolves the issue)-
So restarted successfully –did the trick to me, the job completed successfully-


But still I have doubt in my mind to resolve this problem without recycle of services or is that the permanent solution or any other ways to resolve? –Let me try one more time and will post my outcome.

Bottom Line.
To get the job owner(s)
Use MSDB
GO
Select a.name [JobName],a.owner_sid, b.sid, b.name [OwnerName]
From msdb..sysjobs a
Join sys.server_principals b
on a.owner_sid=b.sid

No comments: