Blog de Humpty

Express your heart's desire

Recent Posts

Tags

Email Notifications

People

Cool Sites

Archives

Database woes

Why oh why must Microsoft release such a shoddy management tool for SQL Server 2005? The tool I'm referring to is, of course, the "wonderful" SQL Server Management Studio. The first problem is that it's written in .NET. Now I love .NET, truly, it makes writing programs and web sites so much easier than other frameworks, and I love programming in C#. The problem really is the DataGridView control in .NET 2.0. It renders horribly slow so moving around data sets with it is a pain in the arse. Anyway, that's a small issue compared to my biggest gripe with Management Studio. The stoopid tool just cannot export or import data for anything but dead simple databases.

So here's my dilemma. Trying to move the Community Server database for this blog and my forums to a new web host. Management Studio offers Import / Export data, Copy Database, and Backup / Restore. None work but I'll take you through my ordeal as to why.

Import / Export Data

The first choice really for me because Enterprise Manager for SQL Server 2000 worked wonderfully doing this. Unfortunately Microsoft, in their infinite wisdom, decided to remove the ability to transfer objects, you can only transfer tables and views. Who thought up this crap!? So to get around this deficiency you have to right-click your database, choose Tasks, and Generate Scripts to get a script that creates all the objects in your database sans any data. You run said script on your destination database and then you go ahead with the Import / Export operation.

Not so fast there partner. If you happen to have, say, 103 tables to copy that's a lot of data to move so the Import / Export wizard wisely advises you to check the "Optimize for many tables" checkbox. So you do and, and this is important, if this is not your first time moving data then your target database will already have data in it so you need to also check the option to delete all rows and enable identity insert. So you go ahead with the transfer and you get an error on the first table: cannot insert duplicate rows, violation of primary key. "What?", you say. "I thought I told you to delete all the rows first, if there's no data how can there be duplicates?", you think. No use getting angry cuz there's nothing you can do about it, the stoopid wizard is just not going to delete the rows first so it's always going to fail.

Okay, so after much much, and I mean much, swearing you calm down enough to realize you can just delete all the rows in the target database yourself since the wizard can't do it. I used this script for that, thanks to all newsgroup posters, you guys rock.

-- Disable all constraints
select 'alter table ' + table_schema + '.' + table_name + ' nocheck constraint all'
from information_schema.tables
where
  objectproperty(object_id(table_schema + '.' + table_name), 'IsMSShipped') = 0
  and table_type = 'BASE TABLE'

-- Generate delete all rows
select 'delete from ' + table_schema + '.' + table_name
from information_schema.tables
where
  objectproperty(object_id(table_schema + '.' + table_name), 'IsMSShipped') = 0
  and table_type = 'BASE TABLE'

-- Reenable all constraints
select 'alter table ' + table_schema + '.' + table_name + ' with check check constraint all'
from information_schema.tables
where
  objectproperty(object_id(table_schema + '.' + table_name), 'IsMSShipped') = 0
  and table_type = 'BASE TABLE'

This gives you a result set that you can just copy and paste into a new editor window and execute. First it disables all the constraints on your tables so you can actually delete all the rows in them without warnings and errors, secondly actually deletes them, and thirdly after your data is across reenables constraints. Neat, good. So now I can actually use the Import / Export wizard to transfer the rows and not worry about deleting all the rows first, but enabling identity insert is still important. So the wizard actually completes!! A fool and his elation are soon parted however when he realizes tables with identity columns have all new values in them... Sad Stoopid wizard didn't enable identity insert so now my site doesn't work anymore! Super Angry Upon further testing in transferring only one table with identity insert on reveals the wizard does actually do this, but apparently only if you transfer one table. It actually could be higher than that but no way was I going to transfer 103 tables one-by-one.

At this point I've spent damn near the entire day, literally, working on this before finally coming to the conclusion the Import / Export wizard is just useless. To make a long story short I ended up using xSQL Data Compare to get my data across, finally. Another tool of mention is SQL Manager 2005 because it can generate a script that will insert all your data for you! Both products have freeware lite editions but I used them in their trial periods to get full functionality, hehe.

Copy Database

This Management Studio option is just useless because you have to be in the sysadmin server role to use it. Next.

Backup / Restore

Sadly, the data transfer options of Management Studio are so poor that backing up and restoring your entire database on the web host has become the de facto standard for moving your data. This works but does require to coordinate with the web host. Unless you happen to be at one of the web hosts that offers this as an automated feature. Of course, if you're in my case and can't even get your web hosting company to even talk to you *cough ASPnix* then even this option is not for you.

SQL Server Integration Services (SSIS)

Some people might want to chime in that the Enterprise Manager option of transferring objects is still there but just moved to SSIS. Well, yes, but it don't work. I tried everything I could think of to transfer data and I always had my transfer task highlight in yellow with some warning. I gave up.

Posted: Sun, Sep 16 2007 7:30 PM by Humpty | with 9 comment(s)
Filed under:

Comments

Blog de Humpty said:

Oh what a weekend I've had. Let me just say that ASPnix sucks as a web host! They were the latest hoster

# September 16, 2007 7:47 PM

John aka Frustrated with SQL 2005 ;) said:

Oh man, believe me I feel your pain. I can't believe how broken some of the functionality that I took for granted under SQL 2000 is now, oh well c'est la vie.

Thanks for the chuckle, there was definitely much swearing on my end.

# September 28, 2007 7:10 PM

sql2005Hater! said:

Funny stuff.  You've maintained a much more positive attitude than I am able to when dealing with this steaming pile of crap they call the management studio.  I can't believe this is a 2 year old product.  The management tools are not even beta quality.  

# September 28, 2007 7:20 PM

Humpty said:

Glad my pain could bring you a chuckle. Heck, after rereading what I wrote even I'm laughing. What a loser I was to think Microsoft could do something right. :P

# September 29, 2007 2:47 AM

John aka Frustrated with SQL 2005 ;) said:

Just wanted to share with you that we managed to get around our Import/Export problem by installing the 'Microsoft SQL Server 2000 DTS Designer Components for SQL 2005' and reverting back to SQL 2000 DTS packages for any data transfers that involve many tables. The SQL Server 2000 DTS Designer Components provide legacy support for - surprise, surprise - SQL 2000 DTS packages under SQL 2005. All functionality appears to be the same as it was under SQL 2000. More information can be found here: http://www.microsoft.com/downloads/details.aspx?FamilyID=50b97994-8453-4998-8226-fa42ec403d17&DisplayLang=en#Overview The package can be downloaded here: http://download.microsoft.com/download/2/7/c/27c60d49-6dbe-423e-9a9e-1c873f269484/SQLServer2005_DTS.msi One note, and it's an important one: We've found that SQL 2000 DTS packages will work to transfer data between tables on SQL 2005 servers and from SQL 2005 to SQL 2000, BUT NOT from SQL 2000 to SQL 2005. I'm slightly less frustrated, but still baffled that something that worked so well in the past is now so broken. In any case, I'm just glad it's working ;)
# October 3, 2007 6:34 PM

Humpty said:

That's a pretty neat tip, thanks! I've known about those components but never thought to use them to transfer data between 2005 databases. Most interesting. Definitely have to give this a go the next time I want a backup of my database from my web host.

# October 3, 2007 7:47 PM

Polk said:

ASPnix is now different and it's absolutely not true what you said about them.

ASPnix offers new Hosting Plans to meet today’s market demand and clients’ expectations.

Shared Plans feature unique Unlimited Bandwidth – No throttling – No kidding!

Reseller Plans feature plans with much bigger disk space.

Virtual Server evolved into 160GB SCSI Disk drives and Terabyte of Bandwidth.

ASPnix Support is now more responsive with less than 15 minutes response time on email and quick replies on Messenger/Online Chat. We now also have Toll Free phone number for Support.

http://aspnix.com

# December 22, 2007 12:31 AM

Humpty said:

Hehe, I guess you work for ASPnix, Polk, seeing how your name points to them and your message sounds like a bullet point list of features. :) It's okay, I'll let your message/ad stand so that it serves to illustrate how your company goes around the Internet trying to cover up bad messages people say about it. On your own site you can delete disparaging forum threads but on my site, ha, no such luck baby. :)

Your company may very well be different now, but when I wrote what I wrote it was very much true. You, me, and many former customers know it. ;)

# December 22, 2007 11:34 AM

Sharon said:

We are having major time-out issues with aspnix.  It is unfortunate but we can't operate under these conditions.

# January 5, 2008 3:04 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Enter the numbers you see in the image: