Blog Splash

Restoring a SQL Server Database that Is Missing the Log File

by Suojatar Tuesday, January 26, 2010 9:31 AM

To restore Database without the LDF file:

  1. Create a dummy database with the same name.
  2. Stop SQL Server and replace the dummy MDF with the one in question, leaving the dummy LDF file intact.
  3. Restart SQL Server – the database will appear in the Enterprise Manager with a gray icon, as "Suspicious".
  4. Switch on the "Emergency mode" for this database by running the following script:
    EXEC sp_configure 'allow updates', 1
    RECONFIGURE WITH OVERRIDE
    GO
    
    BEGIN TRAN
    
    UPDATE master..sysdatabases
    SET status = status | 32768
    WHERE name = 'your_name_here'
    
    IF @@ROWCOUNT = 1
    BEGIN
       COMMIT TRAN
       RAISERROR('emergency mode set', 0, 1)
    END
    ELSE
    BEGIN
       ROLLBACK
       RAISERROR('unable to set emergency mode', 16, 1)
    END
    GO
    
    EXEC sp_configure 'allow updates', 0
    RECONFIGURE WITH OVERRIDE
    GO
  5. Stop SQL Server.
  6. Rename or remove the Log File.
  7. Start SQL Server.
  8. Create the new Log:
    DBCC REBUILD_LOG
    (
     'your_name_here',
     'C:\Program Files\Microsoft SQL Server\MSSQL\Data\your_name_here_Log.LDF'
    )
    
  9. Set the Multi-User mode (otherwise the database will appear as (DBO Use Only):
    ALTER DATABASE your_name_here SET MULTI_USER
  10. Remove the emergency mode:
    EXEC sp_configure 'allow updates', 1
    RECONFIGURE WITH OVERRIDE
    GO
    
    BEGIN TRAN
    
    UPDATE master..sysdatabases
    SET status = status & ~32768
    WHERE name = 'your_name_here'
    
    IF @@ROWCOUNT = 1
    BEGIN
      COMMIT TRAN
      RAISERROR('emergency mode removed', 0, 1)
    END
    ELSE
    BEGIN
      ROLLBACK
      RAISERROR('unable to remove emergency mode', 16, 1)
    END
    GO
    
    EXEC sp_configure 'allow updates', 0
    RECONFIGURE WITH OVERRIDE
    GO

* If for some reason it is impossible to rebuild the log file, after restarting SQL Server (step 7) the Import data functionality in Enterprise Manager will be available. It is useful to create another empty database and import the data and objects into this new database. Use the "Copy database objects" (third option) to copy tables, stored procedures and data. It may be necessary NOT to copy database roles and object-level permissions, as well as SQL server logins as this may cause the transfer to fail. Copying any stored procedures referring to non-existent db objects will also fail.

N.B. Graphical representation of a database running in Emergency mode is not available in Enterprise Manager, however, the structure of tables can be seen (and scripted!) in Query Analyzer.

Longing for KO Approach 0.4.4

by Kerido Wednesday, January 20, 2010 3:25 AM

We're working hardly on a new release of our flagship product – KO Approach. This release is going to catch up with all the new things that occurred to the Windows desktop computing world so far. The product is finally compatible with Windows 7 which will enable the users of this new OS to open files and folders even quicker!

Approach Items is being redesigned to display user-selectable items. From now on, this feature will be fully extensible allowing developers to provide custom content to Approach Items. As an example, we've included a custom item displaying a list of recently used commands from the Run dialog box. With these new concepts, the user will be able to better organize most frequently accessed items, files and folders.

We've added new options into Titlebar Menus to improve user experience. Browse the entire folder hierarchy, from Desktop to the current folder, with CTRL+click on an Explorer window's title bar. Instruct Titlebar Menus to order items as you like: parent-to-child or child-to-parent. The current folder can also be automatically highlighted.

As usual, Scope and InstantWave, the two companions to KO Approach, allow for previewing graphics files as well as playing sound files, right from KO Approach menus! And there are more plugins coming soon!

Approach will consume even less resources thanks to advanced optimization techniques. But most importantly, upgrading to KO Approach 0.4.4 will be completely free!

git: Archiving Files Changed Between Two Revisions

by Kerido Monday, January 18, 2010 8:48 AM

Just recently I started using git and I'm pretty excited about it. Today I needed to obtain a ZIP archive containing only files that were changed or added between a known revision and the current head (I believe, that's roughly the same as trunk in SVN). The solution I came upon is not fully automated, but it's still a HUGE time saver:

  1. Obtain a list of edited files:
    git diff --name-only HEAD __TAG_OR_REVISION__ > out.txt
    After running this command the file out.txt will contain the list of modified file names (including deleted ones), one per line.
  2. Open the out.txt file in a text editor and merge the contents into one line (i.e. replace CR/LF with a space). I also had to manually remove a few files which I didn't need for the archive.
  3. Copy this huge line to clipboard.
  4. Finally, generate the archive:
    git archive --format=zip HEAD __PASTE_HERE__ > out.zip

I'm not a command line expert and I'd love to know a better way. I'm sure it's possible on Linux, but I primarily use Windows, so it might take a cmd.exe geek to sort things out.

A Phrase of Inspiration

by Kerido Monday, January 18, 2010 7:06 AM

This is a phrase that came to me after watching Seth Godin's inspiring video Ideas That Spread, Win:

Many ideas were born from sharing the idea that ideas can be shared.

Haiti Earthquake Relief

by Kerido Monday, January 18, 2010 1:46 AM

A great place to help the children from Haiti is the Save the Children fund. They accept PayPal, Amazon payments, and Google checkout. Maybe it's more convenient that the direct link that Google shows.

Tags:

Personal