Tag: administration

  • Attaching an MDF with no Log (AdventureWorks)

    Attaching an MDF file without an LDF file can be a little tricky. I had to go through this recently when I downloaded the AdventureWorks2008R2 database, which was just an MDF file. I know I’ve done this before, but I had to stop and look things up, which means that I should blog about it (hint, hint).

    How do I attach a new database?

    If I go into SSMS, I can pick the “Attach” dialog by right clicking the “databases” folder.

    attach1

    Once I pick my MDF, I see the dialog populated.

    attach2

    However if I click “OK”, I get an error.

    <mini-rant>

    Don’t click OK for precisely this reason. If there’s an error, it can be hard to figure out what happened, and the error handling in SSMS isn’t the greatest. I’ve even seen people click “Cancel” without realizing there was an error”.

    If you use the GUI, please click the “script” button instead and cancel out of the dialog.

    </mini-rant>

    attach3'

    The error occurred because the log file didn’t exist. If you select the log file in the lower dialog, and click Remove, you can use the GUI here.

    However removing the log file and pressing the click button gives me this code:

    USE [master]
    GO
    CREATE DATABASE [AdventureWorks2008R2] ON 
    ( FILENAME = N'D:\SQLServer\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorks2008R2_Data.mdf' )
     FOR ATTACH
    GO

    .csharpcode, .csharpcode pre
    {
    font-size: small;
    color: black;
    font-family: consolas, “Courier New”, courier, monospace;
    background-color: #ffffff;
    /*white-space: pre;*/
    }
    .csharpcode pre { margin: 0em; }
    .csharpcode .rem { color: #008000; }
    .csharpcode .kwrd { color: #0000ff; }
    .csharpcode .str { color: #006080; }
    .csharpcode .op { color: #0000c0; }
    .csharpcode .preproc { color: #cc6633; }
    .csharpcode .asp { background-color: #ffff00; }
    .csharpcode .html { color: #800000; }
    .csharpcode .attr { color: #ff0000; }
    .csharpcode .alt
    {
    background-color: #f4f4f4;
    width: 100%;
    margin: 0em;
    }
    .csharpcode .lnum { color: #606060; }No mention of a log file. If I run this I’ll get an error in the messages pane, but the database will attach:

    File activation failure. The physical file name "C:\Program Files\Microsoft SQL Server\MSSQL11.DENALIRCO\MSSQL\DATA\AdventureWorks2008R2_log.ldf" may be incorrect.

    New log file ‘D:\SQLServer\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorks2008R2_2_log.ldf’ was created.

    Converting database ‘AdventureWorks2008R2_2’ from version 705 to the current version 706.

    Database ‘AdventureWorks2008R2_2’ running the upgrade step from version 705 to version 706.

    That works well, but what about the rebuild log option?

    If you look in the CREATE DATABASE topic, you’ll find the option ATTACH_REBUILD_LOG. What if I use this?

    create database AdventureWorks2008R2_2
     on ( filename = 'D:\SQLServer\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorks2008R2_Data2.mdf')
      for attach_rebuild_log

    .csharpcode, .csharpcode pre
    {
    font-size: small;
    color: black;
    font-family: consolas, “Courier New”, courier, monospace;
    background-color: #ffffff;
    /*white-space: pre;*/
    }
    .csharpcode pre { margin: 0em; }
    .csharpcode .rem { color: #008000; }
    .csharpcode .kwrd { color: #0000ff; }
    .csharpcode .str { color: #006080; }
    .csharpcode .op { color: #0000c0; }
    .csharpcode .preproc { color: #cc6633; }
    .csharpcode .asp { background-color: #ffff00; }
    .csharpcode .html { color: #800000; }
    .csharpcode .attr { color: #ff0000; }
    .csharpcode .alt
    {
    background-color: #f4f4f4;
    width: 100%;
    margin: 0em;
    }
    .csharpcode .lnum { color: #606060; }If I run this, I get essentially the same messages:

    File activation failure. The physical file name "C:\Program Files\Microsoft SQL Server\MSSQL11.DENALIRCO\MSSQL\DATA\AdventureWorks2008R2_log.ldf" may be incorrect.

    New log file ‘D:\SQLServer\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorks2008R2_2_log.ldf’ was created.

    Converting database ‘AdventureWorks2008R2_2’ from version 705 to the current version 706.

    Database ‘AdventureWorks2008R2_2’ running the upgrade step from version 705 to version 706.

    I’m not sure why this option exists, or if it’s been deprecated in 2012 since the functionality appears to exist in FOR ATTACH. The documentation mentions that if the log file is not there, it will rebuild. I guess this is included in case you wish to force a rebuild, which is a good thing.

    In any case, if you run into issues attaching a database with the GUI, this should help you.

  • The Dark Side

    I went to the Dark Side recently and enjoyed it.
    I went to the Dark Side recently and enjoyed it.

    Recently I was invited to speak at the Rocky Mountain Oracle Training Days. It was part of some cross platform talks that have happened in Denver, with some Oracle professionals coming to our last SQL Saturday in Denver. I was happy to oblige, and ended up spending part of two days at the small conference. I was a little nervous beforehand, unsure of how SQL Server talks might be received at an Oracle event. There’s a fair amount of animosity between the companies and that seems to bleed over to the professionals working on these platforms. I’ve made my share of Oracle jokes in the past, though all in fun.

    It was interesting to sit and talk with some of the Oracle DBAs attending. For the most part, they have the same problems as SQL Server DBAs, and seem to approach things in a similar manner in terms of indexing, tuning SQL and more. They have the same types of problems, with similar solutions, though the details are different. And, of course, the Oracle solutions tend to be more expensive. I did hear about one thing that I wish was a part of SQL Server: mirroring of log files. I haven’t had many issues with log files, but as databases get more critical, this seems like an enhancement to SQL Server that would make sense.

    One of the interesting things I did hear about was from a cross platform DBA who didn’t have a unified directory services structure and struggled with the SQL Server authentication when clients came from non-Windows systems. This person loved the integration of the Microsoft stack, but moving outside of their technology resulted in lots of challenges. This is one of the areas where I think Microsoft has fallen down in the past, in not supporting a variety of clients well. Even today there are issues when you leave the IE browser in some applications.

    It was a good conference, with so many people facing the same types of concerns over limited resources, technology changes, and job security. Most of the attendees just want to learn more, get better at their jobs, and stay employed. I’m glad I had the chance to attend, and hope I get to go back next year.

    Steve Jones


    The Voice of the DBA Podcasts

    We publish three versions of the podcast each day for you to enjoy.

  • Database Maintenance Essentials – Oracle Training Days

    Presented at Oracle Training Days, 2013

    Abstract: SQL Server requires a minimal level of maintenance to ensure that the platform functions at an optimum level without any unnecessary outages or problems. This talk will look at the basics of the maintenance operations that should be performed on SQL Server on a regular basis. The topics covered include:

    • Managing MDF and LDF Files
    • Managing Indexes
    • Maintaining Statistics
    • Checking for Corruption
    • Creating Backups That Will Restore
    • Managing Maintenance Jobs

    I cover the reasons why maintenance is required and include a number of references to help you enable this maintenance in your environment.
    In some presentations I will also cover the Red Gate tools that make this maintenance easier to perform. This is optional.

    Slides: Download the PPTX

    Level: 100

    Length: 60 minutes

  • The Cloud in Large IT Shops

    Toyota is focusing on software the enhance its business.
    Toyota is focusing on software the enhance its business.

    I’ve seen many presentations and talks from companies that are using cloud services to replace traditional IT infrastructures and lower their costs. Often these presentations are from smaller companies that don’t want to hire an IT administrator, or buy server or learn how to host and manage that hardware. Plenty of small companies would prefer that each employee manage their own laptop and nothing more.

    However many of those strategies don’t match the situation for large companies. Once you’ve hired an IT staff and made an investment in hardware and facilities, can the cloud really help you? I had my doubts, but this article about Toyota makes me rethink those doubts, or at least many of them.

    The lesson from the article, for me, is that Toyota’s IT group is learning to be a lean part of the business; they are building applications and tools that internal employees and customers can use to work better. They’re not acting as a separate business that needs to build software and also manage and administer the platforms that run those applications. By building software for Toyota and its customers, and outsourcing other functions, the Toyota IT group is more focused.

    Will this work in the long term? Will there be security issues from hosting email and other applications? Possibly, but I’m not sure if the problems and issues they encounter will be any worse than those problems that might come from managing all the hardware themselves.

    I still think the idea of container data centers, running cloud platform software, makes sense for large companies, but I suspect that even if they host an application like Salesforce.com, the administration of the software will come from Salesforce and not internal IT server administrators.

    Steve Jones

    Advertisement: If you are looking to speed up your development process and reduce mistakes with Continuous Integration, you might be interested in thesewhite papers on automated deployment and CI for databases from Red Gate Software. It talks about how you can set up a process using various tools.

    The Voice of the DBA Podcasts

    We publish three versions of the podcast each day for you to enjoy.