Author: Calin OPREA

  • Say What? – “Management Studio: must be set in single thread apartment (STA) mode before OLE calls can be made”

    Yes, I have another couple of minutes to document this weird message.

    I was trying to access the database properties for one of our databases. Guess what: I couldn’t as there was no owner! Well, the easiest thing to do is to alter the authorization on the database; as you may have guessed it already, I didn’t pay any kind of attention to the error message, and quickly jumped to the magic world of… creating a diagram (actually the mouse pointer was in the wrong location, I just clicked, so it was not my fault, right?). Well, this time I got to do a print screen:

    OK, now let’s copy that stupid message without reading it, select some random text from it, and do a blind search in hope for sheer luck. Click the Copy sign… and there you go, another weird stuff:

    Now this one finally got my attention.

    It turns out that it used to be a bug (check here), but it was supposed to be fixed. Well, apparently not all the cases were covered.

    My wild guess is that:

    If you have a database that does not have an owner (how about someone who left the company and we removed the user account – I need to check this) and you want to create a diagram, you will see the first pop-up error message. Trying to copy the message itself (via the Copy feature – yeap, those little sheets of paper in the lower-left corner) will yield the second error.

    Of course, the solution is the most difficult one:

    ALTER AUTHORIZATION ON DATABASE::MyDB TO sa;

    I hope it helps.

    Best regards,
    io

  • Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. Error source: Microsoft OLE DB Provider for SQL Server – revisited

    This blog post is waiting for me to have some time for the past couple of months by now. It did bite me back then, and so it did yesterday.

    “Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. Error source: Microsoft OLE DB Provider for SQL Server” – now, I must emphasize that I’m not going to reproduce the plethora of info that is present out there already, but instead I might be among the few selected ones that indeed had issues with AD domains. If you’re curious about that, read on; if you’re looking for how to enter some lines of code in some connection string, you better go have a coffee or something.

    Background: the company that I work for, migrated all their SQL Server 2005 servers (with DAS – Direct Attached Storage) to SQL Server 2008 clustering (on SAN). This obviously means a lot (I mean A LOT) of fun, such as deprecated code, and so on. Besides this, one of the required steps is to swap the IP addresses between the SQL Server 2005 machine and the SQL Server 2008 resource on the cluster (of course, anybody knows that SQL Server 2008 is just a resource on a 2008 cluster, right? – I learned this the hard way).

    And now for the fun:

    “ONLY jobs that need to run to C:\Program Files (x86)\Microsoft SQL Server\80\Tools\Binn\DTSRun are failing.
    The ones that are running C:\Program Files (x86)\Microsoft SQL Server\90\DTS\Binn\dtexec are running fine.
    Secondly, the ones running under 80\Tools are the ones using the server IP (10.0.0.31). when you ping the IP address, it still returns SQL03DB as the server.”

    Rough translation of the above: all the jobs that running DTSX packages are running fine, while all the jobs that are running DTS (SQL Server 2000 – yes, I know, that old) are failing in SQL Server 2008. Besides that, when I run ping –a 10.0.0.31, I still get the name of the SQL Server 2005 machine, instead of the SQL Server 2008 cluster resource.

    This is something that happened early May, and I completely forgot about it. And it happened again yesterday.

    Sorry for all that blur stuff, but this is a prod machine. Anyway, as you can see, the IP address of my SQL Server cluster resource is 10.0.0.10.

    Now, if I ping –a 10.0.0.10, I get the following:

    So instead of getting something in the line of “28DBCLU”, I still get the old SQL Server machine, which used to be “01db”.

    Again, oddly enough, this manifested itself only for the DTS packages, which are running DTSRun, found in the \80 folder.

    Solution? A very simple one, just ask the sys admins to make the necessary changes in the DNS (yes, that DNS, related to AD, DHCP, all that jazz). Also, it would be very helpful not to have hard-coded values in your hosts file.

    And for the grand finale: I posted a question on Twitter, under #sqlhelp, asking whether I should have my system databases on SAN (which mean automatic failover in case something goes wrong with the active node), or if they should be on the default installation path (yes, that Program Files thing). While there was a little variation of the answers, my personal choice is to have them automatically fail over. Just imagine what would happen if you have a failover and the msdb
    and master databases are not the same.

    Best regards,
    io

  • My mail to SQL Sentry that will win me (yeah, right) a free seat to SQL Skills training!

    The amazing guys @SQL Sentry (www.sqlsentry.net)  are giving away a chance to win a free seat to SQL Skills Internals and Performance training (check out the details: http://www.sqlsentry.net/sqlskillsimmersion.asp).

    Of course, I decided to give it a try, so I wrote to the guys; you can check it below:

    “Hello there.

    Now, last night at around 2:30 AM I stepped down of bed, as the little ones (we have two kids) kept kicking me in the head for far too long. Since I’m a hopeless DBA, the very first thing to do is to open the laptop and check on the emails. I almost fell down from chair when I saw Paul’s email regarding your offer. And I said to myself ok, I’m still asleep and dreaming, let’s read that again in the morning. Which I did. And there it was, the offer.

    I so MUST HAVE to be there! Let’s see why:

    I live in Romania, which, by all standards, had a strict comunist regime until 1989. While it was strict in regards with computers (we didn’t even have a word for computer), there was a plethora of underground illegal stuff, such as cable TV. This way we got introduced to good movies with hot chicks. Movies that immediately after the Romanian revolution (December 1989 the revolution, early ’90ies for the rest of the story) turned into even more good looking chicks. Of course, the entire gang fell in love with such angels. Even back then we knew that we had no chance with them, but at least we could try to get something similar in Romania.

    By all standards, none of us were quite hot-shots, so we decided that the best way to pick up gorgeous girls is to have money – a truth that happens to be the same worldwide. It also happened that unfortunately all of us were raised to be honest, not to steal, all that jazz, so we realized that we would have to make a career that would pay enough money to stand out from the crowd. There you go, we got into IT.

    This was a big mistake for several reasons: as everywhere else in the world, the true hot shots never go to work, ever; as they say, if you work, you don’t have time to make money. But the worse was to happen: we all fell in love with this new… thing, which was computers. Not to mention that back then the Internet changed it all (yeap, I’m that old, I keep telling that Internet and internet are not the same). So before any of us could realize what’s happening, we pretty much forgot about the movies and the hot chicks and got our hands dirty into all sorts of things, such as networking (myself included) and programming (myself excluded).

    Fast forward a few years later, around the beginning of the millennia, most of us were working in the IT field (by the way, it is still growing exponentially in Romania). Now, there is an old saying: he who can do, will do; he who cannot, will teach. Of course, most of the gang members got to work, while I got to teach (as a technical trainer in various capacities).

    Quick jump into 2008: I got a job offer as a database administrator in SQL Server. Does it have icons? Can I work with a mouse? Yes. OK, I’m in. It was back then when I fell in love with the damn thing. Then I got to read great blogs from great people, such as Brent Ozar and Paul Randal, just to name a few. Back then, I would have said that thanks to them, I kept my love for SQL Server growing.

    Another quick jump into 2011: I got another job as a SQL Server DBA, but this time the mouse was the least of my worries. Just to give you an example: guys, do any of you know anything about clustering? None of us did. OK, you have three days to pick it up, we’re migrating all of our databases to SQL Server 2008 clusters. We did pick it up.

    This year (2012) I got to TechEd Orlando, only to make a fool out of myself in front of Brent Ozar (if you check his presentation, he makes fun of me for asking for a card to show his card to my wife).

    To conclude: while in 2008 I would have said “thanks to these guys…”, this year I’m saying “because of these guys…”. Because of these guys I still love the damn thing (SQL Server, that is). Because of these guys I’m still wasting nights, trying to pick up things on the fly. You cannot imagine the sheer joy and happiness of my wife when I have to work to replace and consolidate the database servers almost every week-end.

    So, if it’s all because of “these guys“, why not let them handle me? At least in part? They made me forget my initial goal, of being a hot shot, and turned me into some sort of a weird kookoo, trying to do his best. Worse part yet; because of them I got again into training, blogging, and trying to help other people.

    I absolutely need this course (and not only): it will massively shorten the path to great knowledge and less work. I’m planning to that ASAP; right now, the kids are still calling me daddy, but with the crazy hours that I have to put, I’m not sure it will be the case in the near future.”

  • Move cluster group from one node to another

    First off, apologies to the 3 readers I have (I don’t read my blog post, I just write), since all of them are far better than I am when it comes to clustering.

    To cut it short: how can you move ANY resource from one node to another? Namely, the disk witness in the quorum cannot be moved using the Failover Cluster Manager GUI:

    So what to do, what to do? When, after a 1 second Google search, I found couple of resources. Not to keep you too much (if you need to read more than 5 minutes, I’m in deep trouble):

    Cluster.exe <<servername>> group – this one (of course, after you replace <<servername>> with your actual server name) will list all of the available resources:

    Group                    Node    Status
    —————————————-
    Cluster Group            Est21DB Online
    Available Storage        Est21DB Online
    EST20_21Dtc              Est21DB Online
    SQL Server (MSSQLSERVER) EST20DB Online

    OK, so now I have my SQL Server on one node, and the rest of the resources on the other node.

    For the brilliance, I decided to move the “cluster group” resource, since this is going to move everything, right?

    cluster.exe est20_21 group “cluster group” /moveto:est20db – and then let’s run again to check that everything is moved to whatever node I choose (in my case, est20db):

    Group                    Node    Status
    —————————————-
    Cluster Group            Est20DB Online
    Available Storage        Est21DB Online
    EST20_21Dtc              Est21DB Online
    SQL Server (MSSQLSERVER) EST20DB Online

    So I was obviously wrong – moving the “cluster group” did not move anything but the “cluster group”. Aaargh, the shared nothing principle (thank you, Alan Hirt, for your great book).

    So, if I really want to move the quorum drive, I need to move the “Storage” group like this:

    cluster.exe est20_21 group “available storage” /moveto:est20db

    Moral of the story: you cannot move all the resources at once – I personally find “cluster group” to be a bit misleading, but again, I’m less than a novice when it comes to clustering.

    I hope this helps someone out there.

    Best regards,
    io

  • Create SQL Server aliases using registry editor

    Another quick one today: how do I create an alias using the registry editor? If you want to want to ask me why would you do such a thing, it means you’re reading the wrong blogJ.

    To cut it short, here are the entries in the registry:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo] – this is for x64 machines who happen to need a 32-bit alias.
    [HKEY_LOCAL_MACHINE\SOFTWARE\ Microsoft\MSSQLServer\Client\ConnectTo] – this is for either x86 machines, or for x64 machines that need a regular alias.

    Ok, as for how I actually use it:

    Fire up Notepad, make your edits, then save it as <whatevername>.reg. Double click the file and confirm that you want the entries in your registry. You now have a script ready to be deployed across multiple servers.

    I hope this helps.

    Best regards,
    io

  • Error message: “A database snapshot cannot be created because it failed to start” when running DBCC

    I recently learned to hate even more the virtualization thing – once your host fails, guess what, everything else goes downJ.

    Anyway, the topic for today is not related to my personal feelings, but to DBCC failing on one of my servers.

    Msg 1823, Level 16, State 2, Line 1
    A database snapshot cannot be created because it failed to start.
    Msg 5123, Level 16, State 1, Line 1

    The database snapshot for online checks could not be created. Either the reason is given in a previous error or one of the underlying volumes does not support sparse files or alternate streams. Attempting to get exclusive access to run checks offline.

    Pretty much the usual messages you would expect NOT to see when running a DBCC CHECKDBJ.

    Well, and now let me quote Paul Randal:

    the ability of DBCC to create the hidden snapshot is purely based on the file-system allowing it

    … something crashed and caused a hidden snapshot to stay around. In that case another hidden snapshot cannot be created. If this is the case then restarting the server should fix the problem – it’s the only way to remove existing alternate streams.

    (http://www.sqlservercentral.com/Forums/Topic450261-146-2.aspx#bm477512 – this is the source of this particular copy > paste)

    So, if you’ve tried anything else and failed, a server restart might help you outJ.

    Best regards,
    io

  • Error: 17300, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.

    Another quick one for today:

    When you encounter such an error (see the title and the print screen below), you might want to check this first: http://social.msdn.microsoft.com/Forums/en/sqldatabaseengine/thread/b0665753-6bb6-48bb-a938-febc6e942d58

    For the really lazy ones: it’s a clear sign of memory pressure.

    I hope this helps.

    Best regards,
    io

  • Cannot shrink the log – now what

    Happy New Year anyone (and Gong Xi Fa Cai, since it’s rapidly approapching).

    Now this one really asks for a blog post, since I saw it too many times on various forums and I just got it on one of my production servers.

    I just got an alert that we’re running low on space on the BIZTALK machine. So, quick and dirty check:

    Uh-oh, this is not good, 99 MB for the data file and almost 10 times the size for the log file. Since I’m in FULL recovery model, this tells me that there’s no transaction log management (read transaction log backups). Sure enough, when I run:

    select log_reuse_wait_desc from sys.databases
    where name = ‘BAMAlertsApplication’

    I get the following:

    OK, I did a log backup, then I tried to shrink the log file, guess what, I’m still with the same log file size! What to do, what to do…

    Well, run the dbcc loginfo

    And look for the status column, for anything that spells “2” – that is the active portion of the VLF. And now for the culprit:

    Sorry for the ugly print screens, it’s a quick post, I’m in the middle of troubleshooting thisJ.

    Anyway, going back, the last record shows me the status of 2. And it just so happens that whenever you want to shrink your log, it will do it backwards, starting with the VLFs that are at the end. The only condition for the space to be released is that the VLFs are inactive (that is, the status is 0). In my case, I have all the conditions not to have my transaction log shrunk, since the very last VLF is marked as active, so the space cannot be given back to the operating system.

    But I really need that space, what to do, what to do…

    Easy enough, backup the log againJ. And now if I run the same DBCC:

    Now I can try to shrink the log again. And here’s the result:

    Key takeaways:

    • If you are in FULL recovery model and never done a transaction log backup, you either switch to SIMPLE or start doing transaction log backups
    • If you absolutely need to shrink the transaction log (as it was my case, running out of space), check it with DBCC LOGINFO (run this in the context of the database you care about) and check which ones are marked as active.
    • If it just so happens that the last one is marked as active, make a transaction log backup again. And againJ. Until problem is solved – by the way, this goes for servers with very low activity, as it was my case.
    • After the last VLF is marked as inactive, you’re good to shrink the log file.

    I hope this helps some soul out there.

    Best regards,
    io

  • Database marked as suspect?

    I just ran into a situation like this, with the CPLS where I’m teaching: “Calin, you’re the guy I was expecting to call!”. Riiight, all of a sudden there’s big love among us, right? Nope, it was a database that was marked as suspect. For no particular reason.
    Okay, do you have backups? From yesterday. Are you willing to lose one day of work? Yes. And the database was restored. And it worked.
    But guess what, the thing went “suspect” again. And again.
    Do you see a pattern here? I didn’t, but it struck me last night: it was the antivirus!!! Because the machine is not really a server, but rather a Windows 7 x64, they shut it down overnight. When it comes back online, if that stupid antivirus thing was doing some updates to a virus definition (and they seem to do it every 2 minutes these days), when you start the machine, the antivirus kicks in a file scan. Because the SQL Server service is among the last ones to start, guess what, the database files might be locked by the antivirus.
    So, as a conclusion, you might want to check whether you have an antivirus on the box in the first place. If you do, I would say that you include the mdf and ldf files in the list of exclusions.
    I hope this helps.
    best regards,
    io

  • BACKUP DATABASE TO DISK = N‘NUL’ – and misconceptions

    Hopefully this will help someone out there.

    There is a command, BACKUP DATBASE <db_name> TO DISK = N’NUL’ and apparently people either don’t know that is there, or are using it for all the wrong purposes.

    We use this particular command to find out our “golden point”, so to speak, which means that we can find out the maximum throughput when taking a backup.

    To give you an example:

    BACKUP
    DATABASE [test] TO DISK = N’K:\FullBackups\test’
    WITH  COPY_ONLY, NOFORMAT, INIT,
    NA
    ME =  N’test-Full Database Backup’,
    SKIP, NOREWIND, NOUNLOAD
    GO

    This gives me, among other things:

    BACKUP DATABASE successfully processed 1931558 pages in 232.509 seconds (63.122 MB/sec).

    Performing the same script as above, but with ‘NUL’:

    BACKUP
    DATABASE [test] TO DISK = N’NUL’
    WITH COPY_ONLY, NOFORMAT, INIT,
    NAME = N’test-Full Database Backup’,
    SKIP, NOREWIND, NOUNLOAD
    GO

     

    And the result:

    BACKUP DATABASE successfully processed 1931206 pages in 103.030 seconds (146.438 MB/sec)

    So you can clearly see that I can actually achieve a higher throughput, namely shorten the time it takes to backup up my database.

    Okay, now that you know what it does, let’s clear some misconceptions about its use:

    • I saw people using it to clear the DCM pages (basically to make their differential backups smaller) – for this one to be achieved, WITH COPY_ONLY will be removed, of course, since this command preserves the LSN chain intact.
      Why on Earth would you want to do it like this to have smaller differential backups? I thought that backup management relates to full, differential and transaction log backups.
    • I heard people using the same backup device (‘NUL’) to clear their transaction logs – huh? WTF…

    To further develop on the two above: as far as SQL Server is concerned, a backup to ‘NUL’ is just that, a backup. It means that the actual write happened as far as SQL Server is concerned. So when performing a classic restore, you need the last full backup, the last differential backup and all (or some) of the transaction log backups.
    But since you wrote to ‘NUL’, there’s no physical presence of the last full backup, so you cannot restore from it. The same goes with the transaction log backups.

    • I saw people doing BACKUP DATABASE TO DISK = N’NUL’ to test their throughput. And they forgot to put WITH COPY_ONLY. Guess what happened:-).

    Ok, so basically this is a useful tool for measuring throughput, but use it wisely. Also, as I just discovered half an hour ago, it works perfectly on my laptop, but not on production, where I have all kinds of activity on the server.

    BACKUP DATABASE successfully processed 1931206 pages in 103.030 seconds (146.438 MB/sec)– backup to ‘NUL’ device
    BACKUP DATABASE successfully processed 1931558 pages in 92.509 seconds (163.122 MB/sec) – COPY_ONLY backup performed to physical disk (on SAN)

    So my “golden spot” is far below the actual speed of the backup. Makes you wonder, isn’t it? J

    I hope this helps.

    Best regards,
    io