Pixytech

Lead Architect  •  Full Stack Engineer

Category: SQL

  • Repair Suspect mode

    USE Master
    GO

    EXEC sp_configure ‘allow updates’, 1
    RECONFIGURE WITH OVERRIDE
    GO

    BEGIN TRAN
    UPDATE master..sysdatabases SET status = status | 32768 WHERE name = ‘YourDBName’
    IF @@ROWCOUNT = 1
     BEGIN COMMIT TRAN
      RAISERROR(‘Emergency Mode Successfully Set’, 0, 1)
     END
    ELSE
     BEGIN ROLLBACK
     RAISERROR(‘Setting Emergency Mode Failed’, 16, 1)
    END
    GO
    –Stop mssql service

    –Rename the existing LOG file for YourDBName database.

    –Start mssql service

    DBCC REBUILD_LOG(YourDBName,’C:program files….dataYourDBName_log.ldf’)
    GO

    DBCC checkdb (YourDBName)
    GO

    –If DBCC return errors then fix it
    — BEGIN
     ALTER DATABASE YourDBName SET SINGLE_USER
     GO
     –Repair the consistency errors if found by above command
     DBCC checkdb (YourDBName,REPAIR_ALLOW_DATA_LOSS)
     GO
     –OR
     DBCC checkdb (YourDBName,REPAIR_FAST)
     GO
    — END Fix errors finished

    ALTER DATABASE YourDBName SET MULTI_USER

    Article applies to SQL Server 2000

  • Security : SQL Server Passwords

    To securely use SQL Server, Microsoft recommends using Windows Integrated Security. In Windows Integrated Security mode, passwords are never stored as your Windows Domain sign-on is used as the security identifier to the database server.
    Password and login ID of a registered SQL Server user in Enterprise Manager for SQL Server can be easily retrieved using SQL DMO (Distributed Management Object). Create file SQLPasswords.vbs and open it in Notepad. Add the following code and save it:

    
    
    Dim pApplication
    Set pApplication = CreateObject("SQLDMO.Application")
    Call EnumGroups(pApplication.ServerGroups)
    Sub EnumGroups(ByVal pGroups)
    Dim pServerGroup 
    Dim pRegServer 
    For Each pServerGroup In pGroups 
     If pServerGroup.RegisteredServers.Count > 0 Then 
      Msgbox "Group :" & pServerGroup.Name 
      For Each pRegServer In pServerGroup.RegisteredServers
       Msgbox "Name:" & pRegServer.Name
       Msgbox "Login:" & pRegServer.Login
       Msgbox "Password:" & pRegServer.Password
      Next
     End If
     If pServerGroup.ServerGroups.Count > 0 Then
      Call EnumGroups(pServerGroup.ServerGroups)
     End If
    Next 
    End Sub

    the script and this will retrieve the passwords of registered servers using your account. If the ‘Always prompt for login name and password’ checkbox is not set when registering a SQL Server, the login ID and password is weakly encrypted and stored in the following registry key: HKEY_CURRENT_USERSOFTWAREMicrosoftMSSQLServerSQLEWRegistered Server X.

    How SQL Server stores passwords (SQL accounts) : See article at
    http://www.codeproject.com/KB/vbscript/SQLServerPasswords.aspx