Thursday, March 8, 2012

Master Data Services (MDS) Rebuild Subscription Views


--Build Delete Statements
SELECT 'EXEC mdm.udpSubscriptionViewDeleteByID @ID=' + CONVERT(VARCHAR(10), ID) + ' ,@DeleteView=1' FROM mdm.tblSubscriptionView  WHERE IsDirty = 1
--Build Create Statements
SELECT 'EXEC mdm.udpSubscriptionViewSave @SubscriptionView_ID=NULL,@Entity_ID='  + CONVERT(VARCHAR(10), Entity_ID) + ',@Model_ID='  + CONVERT(VARCHAR(10), Model_ID) + ',@DerivedHierarchy_ID=NULL,@ModelVersion_ID='  + CONVERT(VARCHAR(10), ModelVersion_ID) + ',@ModelVersionFlag_ID=NULL,@ViewFormat_ID='  + CONVERT(VARCHAR(10), ViewFormat_ID) + ',@Levels=NULL,@SubscriptionViewName=N''' + Name + '''' FROM mdm.tblSubscriptionView  WHERE IsDirty = 1

Wednesday, November 16, 2011

Master Data Services (MDS) error ERR210055 and how to solve it


If you are me you try to do things differently, most of the time they work out on this occasion something went wrong.

MDS Interface does not let you change the length of an member (Free Text) once you have created. If you know the structure of MDS and how it works you can go to the table in this case tbl_3_38 indentify the column name by using the following query

SELECT a.Name, a.TableColumn, a.DataTypeInformation,*
FROM [mdm].[tblAttribute] a
INNER JOIN mdm.tblEntity e ON a.Entity_ID = e.ID
WHERE e.Name = 'Product'
AND e.Model_ID = 3

Make the changes to the table and the [mdm].[tblAttribute] row and rebuild all your views including viw_SYSTEM_3_38_CHILDATTRIBUTES

Here is where the fun starts when I tried to stage the data I get the following error

Error: ERR210055
Description: An unknown error occurred when staging member
record.
Tips for fixing the issue: If an unhandled exception occurs during the staging
process, all records will be marked with this error.
This error may have nothing to do with records that
display this error.

Against each row, nice. Problem solving time what went wrong.
Find the stored proc that MDS is using that generated the error by doing a text search against all the stored procs in MDS database and the result is udpStagingMemberSave.

Next I had to add the following to code

SELECT ERROR_NUMBER() AS ErrorNumber ,ERROR_MESSAGE() AS ErrorMessage;

to the mdm.udpStagingMemberSave to display the error.

2601       Cannot insert duplicate key row in object 'mdm.tbl_3_38_EN' with unique index 'ix_tbl_3_38_EN_Version_ID_VersionMember_ID'. The duplicate key value is (3, ).

You will have to run mdm.udpStagingMemberSave manually otherwise you will not see the result.
Helpful sql

UPDATE [RegDistMDS].[mdm].[tblStgMember] SET Status_ID = 0, ErrorCode =''
EXEC mdm.udpStagingMemberSave 1, --@User_ID admin user
                              3, --@Version_ID,
                              2, --@LogFlag Defualt
                              39 --@Batch_ID the last one processed

Eventually you find this dynamic sql is causing the error. I’ve highlighted what is causing the issue.

                     INSERT INTO mdm.' + quotename(@Entity_Table) + N'  
                        ( 
                             Version_ID  
                            ,VersionMember_ID 
                            ,AsOf_ID --Use this column to map between new @@IDENTITY and Stage_ID within OUTPUT clause 
  
                            ,Status_ID 
                            ,ValidationStatus_ID 
                            ,Name 
                            ,Code 
                            ,EnterDTM 
                            ,EnterUserID 
                            ,EnterVersionID 
                            ,LastChgDTM 
                            ,LastChgUserID 
                            ,LastChgVersionID 
                            ' + CASE @MemberType_ID  
                                    WHEN @MemberTypeCons THEN N',Hierarchy_ID'  
                                    WHEN @MemberTypeColl THEN N',Owner_ID' 
                                    ELSE N'' 
                                END + N' 
                        ) 
                        OUTPUT inserted.AsOf_ID, inserted.ID INTO #tblMemberID(Stage_ID, ID) 
                        SELECT 
                             ' + @strVersion_ID + N' --Version_ID                          
                            ,NULL -- Set the default Member_ID 
                            ,Stage_ID --AsOf_ID  
                            ,1 --Status_ID 
                            ' + CASE @MemberType_ID  
                                    WHEN @MemberTypeColl THEN N',3 --Set ValidationStatus_ID TO 3 (validation succeeded) for collection members since business rules does not apply ' 
                                    ELSE N',0 --Set ValidationStatus_ID to New AwaitingValidation' 
                                 END + N'     
                            ,Member_Name 
                            ,Member_Code 
                            ,GETUTCDATE() --EnterDTM 
                            ,' + @strUser_ID + N' --EnterUserID 
                            ,' + @strVersion_ID + N' --EnterVersionID 
                            ,GETUTCDATE() --LastChgDTM 
                            ,' + @strUser_ID + N' --LastChgUserID 
                            ,' + @strVersion_ID + N' --LastChgVersionID 
                            ' + CASE @MemberType_ID  
                                    WHEN @MemberTypeCons THEN N',' + ISNULL(@strHierarchy_ID, N'NULL --Hierarchy_ID') 
                                    WHEN @MemberTypeColl THEN N',' + @strUser_ID + N' --Owner_ID' 
                                    ELSE N'' 
                                END + N' 
                        FROM #tblStage  
                        WHERE Status_ID = @StatusOK;



So eventually you will find that that the following index is to blame.

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[mdm].[tbl_3_38_EN]') AND name = N'ix_tbl_3_38_EN_Version_ID_VersionMember_ID')
CREATE UNIQUE NONCLUSTERED INDEX [ix_tbl_3_38_EN_Version_ID_VersionMember_ID] ON [mdm].[tbl_3_38_EN]
(
      [Version_ID] ASC,
      [VersionMember_ID] 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, DATA_COMPRESSION = PAGE) ON [PRIMARY]
GO

Somehow when I used the SSMS in design mode to change the table it overwrote the index incorrectly. Yeah so much joy

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[mdm].[tbl_3_38_EN]') AND name = N'ix_tbl_3_38_EN_Version_ID_VersionMember_ID')
CREATE UNIQUE NONCLUSTERED INDEX [ix_tbl_3_38_EN_Version_ID_VersionMember_ID] ON [mdm].[tbl_3_38_EN]
(
      [Version_ID] ASC,
      [VersionMember_ID] ASC
)
WHERE ([VersionMember_ID] IS NOT NULL)
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, DATA_COMPRESSION = PAGE) ON [PRIMARY]
GO

Wednesday, October 13, 2010

WPF DataGrid Entity Framework 4.0

Tags: WPF, DataGrid, Entity Framework, Detached

When I populate the datagrid with linq + entity framework for example

myModel context = new myModel();
myDataGrid.ItemsSource = from a in context.Apples select a;

and then you create a new record via the DataGrid and you want to handle the event InitializingNewItem. You may want to check what the display order of apples is, you can not check via context as the record/s are detached so you have to look in items. The problem is that the new record is of type MS.Internal.NamedObject not Apple.

So you write the following LINQ query
var MaxDisplayOrder = (from Apple a in myDataGrid.Items select a.DisplayOrderNo).Max();

You run it and get the following error exception:
Unable to cast object of type 'MS.Internal.NamedObject' to type 'Apple'.

To solve this problem use OfType method
var MaxDisplayOrder = (from a in myDataGrid.Items.OfType<Apple>() select a.DisplayOrderNo).Max();

Monday, May 31, 2010

.Net 4.0 Framework GAC Location

The location of the GAC has split with .Net 2.0 – 3.5 Framework remaining where it is
C:\Windows\assembly
And the .net 4.0 GAC location is now
C:\Windows\Microsoft.NET\assembly

Monday, May 24, 2010

VirtualBox using Hyper-v VHD image

Tag: Virtual Box Hyperv
I was sick of using windows server 2008 r2 and wanted to move to window 7(now 10). After reading a few reviews it was clear that VirtualBox works very nicely. So I nstalled VirtualBox on a clean windows 7  machine and copied across a VHD. Setup the virtual machine to use an existing hard drive.
image 
Select Next.
Select Memory.
Select Use an existing hard drive.
Select Add icon and select the desired VHD.
image 
Upon starting the virtual machine I received the following blue screen of death:
image
Error Message A problem has been detected and windows has been shut down to prevent damage to your computer.
If this is the first time you’ve seen this stop error screen, restart your computer. If this screen appears again, follow these steps:
Check for viruses on your computer. Remove any newly installed hard drives or hard drive controllers. Check your hard drive to make sure it is properly configured and terminated. Run CHKDSK /F to check for hard drive corruption, and then restart your computer.
Technical information:
*** STOP: 0x0000007B (0x80786b58, 0xC0000034, 0x00000000, 0x00000000)
Solution
The issue is that hyper-v will only build a bootable IDE hard drive. So when you create your virtual machine you need to make sure that you are not booting the VHD under a SATA Controller
image
but instead use the IDE Controller
image

Wednesday, October 14, 2009

Unit testing SharePoint WSS 3.0 x64 bit

Problem
trying to MS unit test code on x64 bit OS with x64 bit WSS 3.0 installed

[TestMethod]
public void TestMethod1()
{
using (SPSite sp = new SPSite("http://localhost:13000/"))
{
Console.WriteLine(
"Site valid");
}
}

Error Message
Test method TestProject1.UnitTest1.TestMethod1 threw exception:

System.IO.FileNotFoundException: The Web application at http://localhost:13000/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add
a new request URL mapping to the intended application..

Solution
http://community.bamboosolutions.com/forums/t/8179.aspx
download nunit (only 32 bit). Nunit will automatically choose which JIT compiler to use to test the code.

Additional Stuff
Code modification to have both nunit and MS test running together
http://www.martinwilley.com/net/code/nunitmstest.html

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Category = Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestContext = System.Object;
#endif

Sunday, August 9, 2009

Silent Install

download here

As a contractor and also some of colleges, end up building a lot of virtual environments. So after installing Biztalk 2009 for the nth time. I decided to automate the Biztalk 2009 installation (and also Biztalk 2006 r2 and ESB 2.0 Toolkit). I started looking at some products that where available on line but nothing met my needs. The requirements that I was looking for:

autologin – some packages that are installed require reboot prior to continuing i.e. sql2008
config – all data to be stored in a config file and easily customizable.
non msi – not have to install it on a clean machine.

So I build Silent Install. Its still a work in progress but its stable enough to get the job done.

Benifits
· Same dev installation across all environments.
· No missing components.
· Reproducible production installs

image

Currently there are 4 options available:
· Install Biztalk 2006 R2 Dev on win 2003
· Install Biztalk 2009 Dev on win 2008
· Install Biztalk 2009 ESB Tool Kit 2.0
· Create Custom Install

As seen below
image

Some installations require a reboot, so your credentials are required for auto login.image

How things work

I create a vhd (Virtual Hard Disk) with all install files copied onto it (size is ~14GB I would like to put it on the net but due to the size and legal issues that will never happen).

image

The way it works is that you figure how to silently install each application by itself, create a batch and sometimes additional ini/xml data files as well. Once you have created each batch file you need to determine in which order to run them.

image

This is then stored in the app.config of Silent Install.
<Environment name="Biztalk2006 R2" Description="Install Biztalk 2006 R2 Dev on win 2003">
  <applications>
    <application order="1" value="IIS6" />
    <application order="2" value="SQL2005" />
    <application order="3" value="Visual2005" />
    <application order="4" value="Visual2005Sp1" />
    <application order="5" value="SQL2005Sp3" />
    <application order="6" value="Reboot" />
    <application order="7" value="Wss3Sp1" />
    <application order="8" value="Biztalk2006R2" />
  </applications>
</Environment>
<Environment name="Biztalk2009" Description="Install Biztalk 2009 Dev on win 2008">
  <applications>
    <application order="1" value="Powershell" />
    <application order="2" value="Reboot" />
    <application order="3" value="PowershellUnrestricted" />
    <application order="4" value="IIS7" />
    <application order="5" value="Office2007" />
    <application order="6" value="Visual2008" />
    <application order="7" value="Visual2008TeamExplorer" />
    <application order="8" value="Visual2008Sp1" />
    <application order="9" value="SQL2008" />
    <application order="10" value="Reboot" />
    <application order="11" value="SQL2008" />
    <application order="12" value="Biztalk2009Prerequisites" />
    <application order="13" value="Wss3Sp1" />
    <application order="14" value="Biztalk2009" />
  </applications>
</Environment>
<Environment name="Biztalk2009ESBToolKit20" Description="Install Biztalk 2009 ESB Tool Kit 2.0">
  <applications>
    <application order="1" value="Biztalk2009ESBToolKit20" />
  </applications>
</Environment>

Installing/Progress Screen
Once the install button is clicked you will be directed to the progress tab and installation will start. image

Running and things to do after install
Assumptions
Clean install of the OS and has been fully patch/updated.

Install Biztalk 2006 R2 Dev on win 2003
   · prompted at start asking location of i386 dir (not sure where the registry setting for that is)
After install 
· Configure Windows SharePoint Services (need to read and understand http://www.mindsharpblogs.com/ben/archive/2008/03/08/4411.aspx
· Disable the Shared Memory Protocol (not sure where the registry setting for that is) 
· Configure BizTalk Server

Install Biztalk 2009 Dev on win 2008
After install
· Configure Windows SharePoint Services
· Disable the Shared Memory Protocol
· Configure BizTalk Server

Install Biztalk 2009 ESB Tool Kit 2.0
· Guide on how to install ESB 2.0 toolkit

Future enhancements
· check if a program has already been installed.
· mount ISO