Author: Calin OPREA

  • DTS package runs from command line, but fails from SQL Server Agent

    Yet another quick one for you. One of my colleagues was trying to set up a job to run a DTS package (yeap, I know, a bit of a last century stuff). Whenever he ran the package from the command line, everything was running fine. However, when he ran the same package from within a job, it failed.

    Apparently the answer is very simple in our case, as documented in this article. Just to summarize for you: on a 64-bit system, whenever you run the package from the command line (cmdexec), it calls the 32-bit (x86) version of the tool. Whenever you run it from SQL Server agent, it calls the64-bit of the tool.

    I hope this helps.

    Best regards,
    io

  • How can I tell if my restore process is actually doing something

    Just stumbled into this: if you have a large DB to be restored, it might take forever to actually see the progress moving to 10%, 20%, and so on. Yeah, I know, you should never do a restore from the SSMS, but don’t try to tell me thatJ.
    Anyway, coming back to our scenario: if you have started the restore process, it might take quite a while to see that our particular restore is progressing.
    So here’s a quick look at it:

    SELECT GETDATE() as runtime, command,
      total_elapsed_time,
      percent_complete, estimated_completion_time,
      wait_time, wait_type
      FROM sys.dm_exec_requests
     

    You’ll get a whole bunch of stuff, but we’re going to focus on the “command” part of it, because this is of interest for us:

    As you can see, there’s a RESTORE DATABASE at the second column (command, in our script).

    If I want to focus only on that particular command, I simply add a where clause to the above script:

    WHERE command = 'RESTORE DATABASE'

    Of course, in the percent_complete column I get to see something above 0, if everything is ok.

    I hope this helps.

    Best regards,
    io

    Edit: full article here – as usual, PSSQL team rocks.

  • SQL Server 2008 cluster installation – IP address already in use

    A quick one today, but I intend to make a series out of it, especially that we’re having loads of “fun” with clustering: we encountered something in the line: IP Address 192.168.1.100 is already in use. To continue, specify a different IP address”. Okay, I think this one filled the glass of my colleague, but the main idea is related to ARP, as I recently discovered on Joe Sack’s blog.

    One caveat, though: while I can simply tell you to run arp – d or to talk to your sys admins, but you might wanna also check this link that simply says that you might wanna chat with your networking vendor.

    I hope this quick post might be of help.

    Best regards,
    io

  • Side-by-side installation of SQL 2008 R2 and SQL Server 2005

    My wife asked me to install a named instance of SQL Server 2005 Enterprise Edition x64 on top our existing SQL Server 2008 R2 Enterprise x64. HA! As a SQL Server MCT (besides the fact that I did quite a few installs in my time) I should have known better how to do it.

    So here’s the quick list for you:

    • There is no such thing as SQL Server 2005 x64 on Windows 7 x64 – if you check BOL, there’s absolutely no reference of Windows 7 whatsoever (I’ll need to check after SP4 installation, the installed version of BOL). However, as a tip for you, whatever they support on Vista, it will be supported on Windows 7. Bear in mind, though, that for x64 environments, things are going to be tougher for you.
    • On Windows 2008 R2 Enterprise x64, it works like a charm, but with one little caveat: there’s no such thing as SQL 2K5 named instance on the SQL 2K8 R2 default instance. As a matter of fact, you can select to install the SQL 2K5 instance as default.

    Ok, now, presumably you decided to install SQL 2K5 in the same machine with the existing SQL 2K8 R2 (I know, it’s usually the other way around). Couple of things to note:

    • You absolutely need to consider installing the thing as a named instance. Otherwise you’ll run into some interesting surprises when you are trying to point to the default instance using SSMS. Ah, almost forgot, you can connect with either version of SSMS
      to either the default or the named instance.
      As a side note, I just hit an interesting bug, when I double-clicked the Notification Services for the named instance (that is the SQL Server 2005 installation) using the SQL Server 2008 SSMS (yes, sorry, SQL Server Management Studio – I hope there are no more questions about what is SSMS)
    • You absolutely need to consider installing SP3 after you finished installing the SQL Server from the media; of course, you are smarter than I am, you will know that SP4 is out for more than 6 months. Oddly enough, it still doesn’t show on my TechNet Subscription.

    Finally, two minor tips for you:

    • How to obtain the latest service pack for SQL Server 2005 – just replace the “2005” portion with whatever you need and you’ll get to the relevant page
    • I beg that you read their list of suggested improvements, as well as what’s new. Let me give you an example: “Microsoft Update upgrades all instances of SQL Server 2005 to SQL Server 2005 SP4. For example, if you have two instances of SQL Server 2005 that are running on the computer, both instances are upgraded to SQL Server 2005 SP4.” Say what???

    I hope this helps.

    Best regards,
    io

  • Is the primary key always clustered in SQL Server?

    As I was playing in SSMS (SQL Server Management Studio), I created a table using the plain-old T-SQL, and then I decided to create a primary key, the “wizard” way, so to speak.

    Let’s have a repro here:

    CREATE TABLE [dbo].[Employees]
        (
          [empID] [int] NOT NULL ,
          [firstname] [varchar](30) NOT NULL ,
          [lastname] [varchar](30) NOT NULL ,
          [salary] [money] NOT NULL,
        );

    Okay, now, in order to create a primary key on the empID column, I can either:

    Use the following T-SQL:

    ALTER TABLE dbo.Employees ADD CONSTRAINT
    	PK_Employees PRIMARY KEY
    	(
    	empID
    	)

    Or use the wizard:

    • Expand your database node (testdb, in my case), navigate to your table, right-click it and select Design from the menu. Do not worry about the extra menus and buttons that you see, they are installed when you install SQL Toolbelt, a wonderful gift that I have from our friends at Redgate.

    • Select the column header that you wish to be your primary key (that is, in the Designer tab) and then click the Set Primary Key button (should look like this )
    • Click Generate Change Script (right to the left of Set Primary Key). The Save Change Script dialog box is displayed. Right-click and select Select All.

    • Copy the text and close the window by selecting No. Paste the text in a new query window:
    /* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
    BEGIN TRANSACTION
    SET QUOTED_IDENTIFIER ON
    SET ARITHABORT ON
    SET NUMERIC_ROUNDABORT OFF
    SET CONCAT_NULL_YIELDS_NULL ON
    SET ANSI_NULLS ON
    SET ANSI_PADDING ON
    SET ANSI_WARNINGS ON
    COMMIT
    BEGIN TRANSACTION
    GO
    ALTER TABLE dbo.Employees ADD CONSTRAINT
    PK_Employees PRIMARY KEY CLUSTERED
    (
    empID
    ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    
    GO
    ALTER TABLE dbo.Employees SET (LOCK_ESCALATION = TABLE
    )
    GO
    COMMIT


    I can see some problems already with this approach:

    • The first part is that there’s a BEGIN TRANSACTION for all the database properties. Why is this there? I have no idea, but presumably it looks cool, even if useless.
    • The second part is that there’s the ADD CONSTRAINT that goes with PRIMARY KEY CLUSTERED. Clustered? When did I say that? J
    • Lastly, the LOCK_ESCALATION = TABLE might not be the best idea, at least not always

    OK, now that we spotted some issues, I presume it’s safer to go with the script instead of the wizard:

    ALTER TABLE dbo.Employees ADD CONSTRAINT
    	PK_Employees PRIMARY KEY
    	(
    	empID
    	)

    Now I have successfully created my primary key, so let’s go check it:

    • Expand the Employees table, and then expand the Indexes node.

    Shoot, the primary key is still clustered!

    The answer is this: if you don’t have a clustered index on the table and you don’t define your primary key as being non-clustered, it will assume on your behalf that there should be a clustered index on your primary key.

    I hope this helps.

    Best regards,
    io

  • How to Disable NetBIOS on the SQL Server Box

    Today I’ll post a quick one, since a simple Google search (yeah, Bing, sorry) did not yield too many useful results.

    Just as a quick note, make sure you have a chat with your sys admins; they can tell you whether the protocols are needed or not anymore.

    Okay, on with the tip:

    • Go to Device Manager (either right-click My Computer and select Manage from the contextual menu, or go to Administrative Tools > Computer Management. The Server Management dialog box is displayed, as shown below

    • Expand Diagnostics, and then select Device Manager. You will get to see a screen similar with the one shown below:

    • Go to View menu and select Show Hidden Devices – we’re not getting closer to what we need. Expand the Non-Plug and Play Drivers node (that was not there previously).
      Right-click NETBT (if I remember correctly, it’s called NetBIOS over TCP/IP in Windows 2003) and select Uninstall.

    • Pray that you’ll not get a call in the next few days saying: “what did you do, my app stopped working!”

    Okay, now what you’re actually finding by searching Google and Bing:

    • Open Network and Sharing Center and click the Change Adapter Settings. You should see something similar with the dialog box below:

    • Right-click the net adapter (in my case there’s only one, but you need to change the one that is subject to have its properties changed) and select Properties from the contextual menu.

    • Ah, almost forgot, if you need to disable the SMB as well, select File and Printer Sharing for Microsoft Networks and select Uninstall. Moving further, select Internet Protocol Version 4 and select Properties.

    • Click Advanced and then click the WINS tab.

    • Click the Disable NetBIOS over TCP/IP radio button.

    Now you know how to completely disable NetBIOS, or to “suspend” it from the Advanced TCP/IP settings. I would go for the latter, since most likely somebody will call either you or the sys admins telling that there is an app that needs that particular “protocol“.

    I hope this helps.

    Best regards,
    io

  • Hypervisor not running and Intel not carrying

    I must admit that I’m a huge fan of technology, but only from a distance. I decided to build my own mini-server at home, mainly to be able to run various things in a virtualized environment. Okay, how about Windows 2008R2 and Hyper-V? Good to go, since I have it for free as an MCT.

    As for the hardware… well, I’m married, I have two kids, and this automatically qualifies me as the least important living thing around the house. But still, ASUS P8P67 LE, 8 GB of RAM, Intel i5 – a quad core 2400 series, it’s not that bad, after all.

    Hardware

    The first thing I noticed is that all modern motherboards (mobos, as they call them now) display very bright colors when unpacking them – whatever used to be blue when I was young, now is cyan, whatever used to be red or purple is now magenta, and so on. You kinda need a pair of sunglasses in order to assemble your own PC nowadays.

    Secondly, the BIOS is now visual, with all the buttons and the suggestions (they call it BIOS, EFI, UEFI, all sorts of names), so you better have a mouse. Apart from being good looking, I was not able to set my RAID 10, because there was no option to access the RAID configuration. Half a day later, it turned out that I you do a hard reset (clear the RTC RAM in CMOS – a millennia ago we simply said “reset the CMOS”, or “reset the BIOS”) would solve the problem.

    Software

    Okay, I installed Windows 2008R2 Enterprise without a glitch (as compared to Windows 2008 Enterprise, which I’m still trying to install with no success), and I set the Hyper-V role. Since I created my own virtual machines for running Microsoft courses (curses, as they were called, at least for SQL Server 2008 in the early stages of delivering the course, but now they solved that beautifully), I imported them in Hyper-V. And that was all I was able to do. When I tried starting the virtual machine, it gave me what is now the common: “the virtual machine could not be started because the hypervisor is not running”. A quick check would reveal that I need to go to hardware level again (namely BIOS settings), which I did.

    Hardware level again

    Go to BIOS (or whatever that thing is), and under the Advanced Settings, CPU Settings (by the way, you’ll find this only in the Advanced Mode), and there you’ll find among other settings, the two culprits:

    • Execute Disable Bit (enabled by default) – Enables the No-Execution Page Protection Technology. Enables what? What is this? Yes, I know about DEP and stuff, after all I’m also an MCSE, but still.
    • Intel Virtualization Technology (disabled by default) – “allows a hardware platform to run multiple operating systems separately and simultaneously…”. Really? It does? Okay, so this is my best bet, right? Wrong.

    So far I found the following:

    1. You need “execute disable bit” for Hyper-V to run. Check here
    2. Intel Virtualization Technology does nothing in this particular case. I’ll get back to this later. Please remember the motherboard as well: ASUS P8P67 LE.
    3. You cannot have both of them enable. Oh, sorry, you can, but instead of Windows you’ll enter a spiral of BSODs.
    4. Although there is no way to run Hyper-V without the underlying hardware to do so, apparently it was possible in RC0 of Windows 2008. Again, apparently, as I cannot verify the reliability of the source.
    5. Intel provides tools for you to check whether your processor is being able to run the virtualized environment or not. So, software level again.

    Software level again

    http://www.intel.com/support/processors/tools/piu/sb/cs-014921.htm – this is the tool that is actually telling you whether you should further struggle or not with the damn virtualization thing (just note that I’m not talking about Hyper-V now, I’m talking about the whole virtualization stuff). Yppieeee, I’m good to go!!! I can continue on my quest, as per here!!!

    Just a quick note: you’re interested in Intel Virtualization Technology

    Another quick note: you’re interested in “Execute Disable Bit” to be set to “Yes”.

    But wait, something’s fishy here… okay, let’s go for CPUID and their PC Wizard 2010 – and see what’s in there.

    There looks okay, but why take it for granted? Why not try another tool? After all, when you have three reliable sources nothing can go wrong, right? So HW Monitor is the last tool that I’m checking.

    Nice, everything seems to be in order. I’ve set the settings in BIOS, I’ve checked the hardware info with three different tools, so everything seems to be in order.

    I launched again Hyper-V, only to get…

    Conclusion

    “My Asus contact confirms the enabling of VT-D is not complete due to chipset limitation (cannot pass all test items via Intel VT-D test tool)

    After discussing with Intel FAE, it has just officially confirmed to my Asus contact that the VT-D support mentioned on the Intel’s own P67/H67 board spec page is a misprint, and will be removed to avoid further misunderstanding.

    The official support for VT-D begins from Q67 series, and so is vPRO.

    For your reference.”

    This is the actual quote from an ASUS rep.

    So:

    1. ASUS, it’s not a misprint, it’s a failure!!!!! And it costs money!!!
    2. INTEL, the damn chipset is listed as having the VT support!!! And VT-X???? That is so 6 years ago and x86 architecture!!! The rest of the world is now living in the 64-bit space.
    3. ASUS and INTEL, please let everybody know (just do a Google search for P67 and virtualization to see how many of us are suffering) why on Earth this is either supported, or not supported, depending on when you accessed the forums – yet another design flaw?
    4. I know there’s no way I can win against to corporate giants, but at least I want a decent motherboard that actually does what it says in the manual (again, forget the spec page, the thing is in the manual and in my BIOS).
      And I almost forgot, 2 tons of freshly made coffee, 2 cups a day.
    5. Somebody stop that Steve Jobs frenzy: a BIOS with cute graphics? I need a BIOS that works!!!

    My final conclusion is this: I have seen this in a variety of forums, people having major issues, even though the processor seems to be suitable for virtualized environments. The motherboard also has to support it, and as of this writing, you also VT-d, not VT-x (which is the x86 architecture). Putting together apples and oranges will not yield more apples or more oranges.

    The only workaround I found is to use VMware, but still not quite the best idea for 64-bit guest OS-es.

    Best regards,
    io

     

  • top book for free

    http://www.solidq.com/ce-en/News/Pages/Data-Quality-and-Master-Data-Management-with-Microsoft-SQL-Server-2008-R2.aspx – for those who know about Solid Quality Learning, you know what you’ll get. For the rest of you out there, it doesn’t get any better than this.

  • To 32 or not to 32 on Windows 7

    Finally I got 8 GB of RAM on my laptop. That’s a great thing, especially that I have free licenses to pretty much whatever Microsoft has as x64, except that I’m married and this is not quite my laptop, but my wife’s. If you ask anyone on the planet, you are to find out that she has all the brains and the beauty in our home; after all, those who can do, will do, and those who cannot do, will teach.

    To cut it short: I have Windows 7 32-bit installed on my laptop and I want to access all the RAM, without installing Windows 7 x64. How hard can it be? Just run the following at the command prompt:

    BCDEdit /set PAE forceenable 

     

    Of course, the command executes successfully, and after the reboot I’ll be able to access all the memory, right? Wrong.

    Okay, Google is my friend and I search how to access all the memory on a x86 platform. So I get some interesting posts:

    http://msdn.microsoft.com/en-us/library/aa366778.aspx – this article tells me that the absolute maximum memory that I can access is 4 GB in my case. Of course, they must be wrong, so let’s try another post that actually helps me. After all, they are Microsoft, what do they know about Windows?

    http://blogs.technet.com/b/markrussinovich/archive/2008/07/21/3092070.aspx – there’s this guy, Mark Russinovich that explains at a very technical level why I cannot access more than 4 GB of memory on my machine. Very misleading title of the article, and of no help for my caseJ.

    http://www.unawave.de/windows-7-tipps/32-bit-ram-barrier.html?lang=EN – finally! So I can actually do itJ.

    Key takeaways:

    • You can enable access to more than 4 GB; it’s a licensing issue, not an architectural issue. But because you can does not mean that you should
    • If you do it, chances are that your apps are not aware of how smart and sexy you are – this is definitely true for SQL Server. So, if you want to use more than 4 GB for SQL Server (say, 6 GB, as in my case), you need to do the following:

    Enable the Use AWE to allocate memory checkbox, and specify the memory to use (6X1024 MB = 6144 MB) in the Maximum Server Memory text field. That’s it.

    One word of caution: I did not test this, so I have no idea whether is actually working or not; I advise you to do the same thing I do: simply switch to x64 architecture, especially that we’re talking servers and licensing issues here.

    Best regards,
    io

    Quick edit: you do the same by using sp_configure sproc. You simply neeed to enable the advanced options, set the AWE Enabled to 1, and set the memory for Max Server Memory.

  • Tables and space used by them

    This came up when a dear colleague of mine came to her boss and told him that even though the table she just created had only one row, “is taking up much more space than needed” – this is the actual quote.
    Let see what she meant.

    CREATE
    TABLE dbo.Table_1
    (

    large_column CHAR(8000)
    NULL

    )


    ON

    [PRIMARY]

    GO

    I must apologize for the very creative names I’m giving to my tables in my examplesJ. Okay, so now I have one table with no data in it. In other words, it should not hold any space in the database, right?

    There’s one way to tell this (more, actually, but one this is the one that I’m presenting here, since it’s not commonly used), by using sp_spaceused. If I use this stored procedure, I get the following:

    EXEC
    sp_spaceused
    Table_1

    And the result:

    Now let’s insert exactly one record:

    INSERT
    INTO Table_1 VALUES (REPLICATE
    (‘1’, 8000));

    Now let’s execute sp_spaceused again:

    EXEC
    sp_spaceused
    Table_1

    And for the result:

    So I inserted roughly 8 KB and I already used 16 KBJ.

    There’s nothing mysterious here, really, and the main idea is this: the basic unit of storage for SQL Server – and any RDBMS for that matter is a page, which, for SQL Server, can hold roughly 8 KB of data. A logical grouping of 8 pages is called an extent, and the extent comes in two flavors: a mixed extent (at least two objects share pages from that extent) and a uniform extent (all the pages belong to a particular object).

    Armed with this knowledge, this is what happens when you actually insert a row in the table:

    1. The table will need a special page, called IAM page (Index Allocation Map). This particular page will keep track of all the pages that will be allocated to the table, and it is the index_size column in our case (see here for further details).
      Truth be told, in our particular case it does not hold any information about indexes, since there are no indexes present on our table, but that’s ok, since our “table” is not quite a table, but a structure called heap.
    2. Only after that IAM page is created, we can actually insert a record into our “table”. Of course, this means that another page is needed.

    Now you know why your table (heap, really) holds much more storage than actually there’s data.

    Please bear in mind that this is a mini-post, so to speak, since I did not cover anything related to the allocation itself (GAM, SGAM, PFS pages, and so on), but I’ll cover that in a not too distant post.