Tuesday, February 21, 2012

The file 'microsoft.reportviewer.winforms version 9.0.0.0 culture neutral publickeytoken..cannot be opened.



The file 'microsoft.reportviewer.winforms version 9.0.0.0 culture neutral publickeytoken..cannot be opened. Do you want to remove the reference to it from the Recent list?


Recently I did a SQL Server install and everything went fine. But then I tried to run a disk usage report on one the databases and got the above mentioned error

According to a ticket with Microsoft and this is a known issue.
http://connect.microsoft.com/SQLServer/feedback/details/523972/sql-2008-r2-nov-ctp-management-studio-reports-fail-on-opening

You can verify this by checking if you have the following folder.
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\ReportViewer"

There are two workarounds for this issue.
1) Download and install the Reporting Services Report Viewer 9.0. You can download this package from the Microsoft Download Center or by using the following link:
 http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=6ae0aa19-3e6c-474c-9d57-05b2347456b1

2) Additionally you can install "Business Intelligence Development Studio" using the same installation media that you used to install SQL Server. You can also download this from Microsoft's website. I guess you didn't install this while installing SQL Server.

Friday, February 17, 2012

Move clustered index to a new filegroup


Recreating clustered index

Today I had the task of moving the primary key index which is also a clustered index, to a new file group. But before I explain the procedure, it is interesting to note the necessity to do this.

During the planning phase, we had recommended that the table data and the index data be placed on two different LUNs. This would give the best IO performance. But unfortunately the vendor made a slight error in giving us the DDL for the tables and indexes.

The CREATE table command also added the clustered primary key constraints and specified the filegroup reserved for indexes for the clustered index. I guess they thought since our recommendation was to have all indexes on a separate filegroup, they would create the clustered index also on the index filegroup.

But as most of the DBAs know the clustered index is nothing but the table itself. So when the clustered index was created on the index filegroup it moved the data from the data filegroup to the index filegroup. So essentially we ended with both the data and the index on the same filegroup. The data filegroup was unused after this change.

But unfortunately the non clustered indexes had been created and the data was inserted.
Now if I tried to drop and recreate the  clustered index then the non-clustered indexes would be rebuilt twice.
There is no option but to rebuild the non clustered indexes. But if you do not drop the non clustered indexes first then they will get rebuilt twice. Once when you drop the clustered index and the second time when you create the clustered index. To avoid the trouble just drop all non clustered indexes before you drop the clustered index. This way you avoid rebuilding them at least one time.

So I had drop all indexes and then recreate them and this way I could avoid rebuilding the non clustered indexes twice.

Following is the summary of commands that I ran to achieve this.

1)      Script out the CREATE statements for the table including the CREATE statements for the indexes. (Always have a backup plan, if it helps take a backup of the database.
2)      Drop all the non clustered indexes.
            DROP INDEX [AK_Department_Name] ON [HumanResources].[Department]
WITH ( ONLINE = OFF )
3)      Drop the clustered index.
ALTER TABLE [HumanResources].[Department] DROP CONSTRAINT [PK_Department_DepartmentID]
4)      Create the new clustered index
ALTER TABLE [HumanResources].[Department] ADD  CONSTRAINT [PK_Department_DepartmentID] PRIMARY KEY CLUSTERED
(
            [DepartmentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

Do not forget to mention the new filegroup for the primary key index.

5)      Create all the remaining non clustered indexes and specify the index filegroup.
CREATE NONCLUSTERED INDEX [AK_Department_Name] ON [HumanResources].[Department]
(
            [Name] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON,
      ALLOW_PAGE_LOCKS  = ON) ON [INDEXES]