What happens to my SQL Server logins if I change a windows domain username

134

Solution 1

If the login is tied to the domain account, it should be fine because at the basic level it depends on the SID of the user and not the actual username.

If the new username doesn't work, you may have to reset the token cache with this command:

DBCC FREESYSTEMCACHE('USERSTORE_TOKENPERM');

Solution 2

The permissions should continue to work properly, but the username displayed in SQL Server will be the old name in some places until you manually update it.

While the drop/create method will work, and apparently creating a duplicate sql login with same SID appears to work for some here, I recommend just updating the existing login record in SQL Server (tested in SQL 2012).

ALTER LOGIN [DomainName\OldUserName] WITH NAME = [DomainName\NewUserName];

This will cleanly change the existing system login record to reflect the correct new username for that domain user (SID).

Share:
134

Related videos on Youtube

Tilo
Author by

Tilo

Updated on September 17, 2022

Comments

  • Tilo
    Tilo over 1 year

    Im working with automatic code generator for my projects. And im using Zend Framework 2 for File/Class/Method reflection. I need to add elements to returned array:

     public function getServiceConfig()
     {
         return array(
             'factories' => array(
                 'Album\Model\AlbumTable' =>  function($sm) {
                     $tableGateway = $sm->get('AlbumTableGateway');
                     $table = new AlbumTable($tableGateway);
                     return $table;
                 },
                 'AlbumTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new Album());
                     return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
                 },
             ),
         );
     }
    

    I can get 'factories' array, but cannot add new element (functions). (I need to add new element to factories like " 'objectTableGateway' => function($sm){ ... }") After that i write method body like body = var_export(array, true);

    1. if i add just function - function executes;
    2. if i add in quotes - i need manually clean quotes after code writes to file.

    How to solve this problem?

    Only solution i see is generate whole method body as plain text

    • AlexP
      AlexP almost 10 years
      PHP closures cannot be serialized. Why don't you use a \Zend\ServiceManager\FactoryInterface factory class?
    • Tilo
      Tilo almost 10 years
      Because i missed existence of this method :) Thank you!
  • BenCr
    BenCr about 13 years
    are you sure? I'm talking about server level logins, if you look at a server in management studio under the Security folder there is a Logins leaf so I referd to them as Sql Server logins and windows users. Also I'm using application roles for defining permissions but you don't know enough about my applications requirements to say if using windows groups or logins will suit best. However, thanks for your answer.
  • BenCr
    BenCr about 13 years
    Ok, please point out to me the exact line which you think is incorrect.
  • BenCr
    BenCr about 13 years
    Ahh, I see, so your point is that it's a login to sql server that is called a "windows login" because it's associated with a windows domain account. However thats not what that link you've just provided says, under the section "SQL Server-level principal" it has the name "SQL Server Login".
  • Tilo
    Tilo almost 10 years
    I need to write this array element to file. When i execute var_export($factories, 1); it returns: 'Album\\Model\\AlbumTable' => Closure::__set_state(array( ))
  • Jeroen
    Jeroen almost 10 years
    Then I guess you problem is related to this stackoverflow.com/questions/13734224/… this is about serialization, but I think that solution could help you along as well. DaveRandom comment on the answer also explain why you get this.