Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Not able to Login to the database after restoring on the different Server

Not able to Login to the database after restoring on the different Server

Scheduled Pinned Locked Moved Database
databasesysadminhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    indian143
    wrote on last edited by
    #1

    Hi All, I have two database servers, one Dev and another one Test, I made lots of changes on Dev hance I tried to restore the backup of Dev Database on Test Server with same name everything same. Now with the same Credentials Login and Password my web application is failing to access the database on Test, by saying failing to access the Database. Can anybody please help me in getting out of this situation. All I did was, Dev and Test are two different physical servers, took backup of Dev and restored it on the test, now Login fails. Any help a link code snippet or even a suggestion helps a lot. Thanks in advance.

    Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

    M 1 Reply Last reply
    0
    • I indian143

      Hi All, I have two database servers, one Dev and another one Test, I made lots of changes on Dev hance I tried to restore the backup of Dev Database on Test Server with same name everything same. Now with the same Credentials Login and Password my web application is failing to access the database on Test, by saying failing to access the Database. Can anybody please help me in getting out of this situation. All I did was, Dev and Test are two different physical servers, took backup of Dev and restored it on the test, now Login fails. Any help a link code snippet or even a suggestion helps a lot. Thanks in advance.

      Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      After restoring a database I run this script to drop and add the expected users. It assumes the users are already created on the new server. The underlying ID for the user name will be different on each server.

      Declare @Usr varchar(50),
      @SQL as varchar(5000)

      Declare csrPV Cursor Fast_Forward For
      Select name
      From sysusers
      Where issqluser = 1
      and hasdbaccess = 1
      AND name NOT IN ('dbo','IBMSQLDBA')

      OPEN csrPV

      FETCH NEXT FROM csrPV INTO @Usr

      WHILE @@FETCH_STATUS = 0
      BEGIN

      Set @SQL = 'DROP USER \[' + @Usr + '\]'
      Print @SQL
      exec (@SQL)
      
      Set @SQL = 'CREATE USER \[' + @Usr + '\] FOR LOGIN \[' + @Usr + '\] WITH DEFAULT\_SCHEMA=\[dbo\]'
      print @SQL
      exec (@SQL)
      
      Set @sql = 'ALTER LOGIN \[' + @Usr + '\] ENABLE'
      exec (@SQL)
      
      EXEC sp\_addrolemember N'db\_owner', @Usr
      
      FETCH NEXT FROM csrPV INTO @Usr
      

      END
      CLOSE csrPV
      DEALLOCATE csrPV

      Never underestimate the power of human stupidity RAH

      I 1 Reply Last reply
      0
      • M Mycroft Holmes

        After restoring a database I run this script to drop and add the expected users. It assumes the users are already created on the new server. The underlying ID for the user name will be different on each server.

        Declare @Usr varchar(50),
        @SQL as varchar(5000)

        Declare csrPV Cursor Fast_Forward For
        Select name
        From sysusers
        Where issqluser = 1
        and hasdbaccess = 1
        AND name NOT IN ('dbo','IBMSQLDBA')

        OPEN csrPV

        FETCH NEXT FROM csrPV INTO @Usr

        WHILE @@FETCH_STATUS = 0
        BEGIN

        Set @SQL = 'DROP USER \[' + @Usr + '\]'
        Print @SQL
        exec (@SQL)
        
        Set @SQL = 'CREATE USER \[' + @Usr + '\] FOR LOGIN \[' + @Usr + '\] WITH DEFAULT\_SCHEMA=\[dbo\]'
        print @SQL
        exec (@SQL)
        
        Set @sql = 'ALTER LOGIN \[' + @Usr + '\] ENABLE'
        exec (@SQL)
        
        EXEC sp\_addrolemember N'db\_owner', @Usr
        
        FETCH NEXT FROM csrPV INTO @Usr
        

        END
        CLOSE csrPV
        DEALLOCATE csrPV

        Never underestimate the power of human stupidity RAH

        I Offline
        I Offline
        indian143
        wrote on last edited by
        #3

        Yes it did work thank you very much

        Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups