Wednesday, November 28, 2012

MDS - Operation is not valid due to the current state of the objec


If you have a large model and you are trying edit security settings in MDS(Master Data Services) you may get the following error:

An unknown error occurred.

or
Operation is not valid due to the current state of the object

or
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Operation is not valid due to the current state of the object.

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 
[InvalidOperationException: Operation is not valid due to the current state of the object.]
   System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +11371791
   System.Web.HttpRequest.FillInFormCollection() +329

[HttpException (0x80004005): The URL-encoded form data is not valid.]
   System.Web.HttpRequest.FillInFormCollection() +11485906
   System.Web.HttpRequest.get_Form() +157
   System.Web.HttpRequest.get_HasForm() +11486708
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +141
   System.Web.UI.Page.DeterminePostBackMode() +100
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +259

Solution
Thanks to the MS MDS support team you need to add the following to the web.config file located C:\Program Files\Microsoft SQL Server\110\Master Data Services\WebApplication

<configuration>
<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="2000" />
</appSettings>
</configuration>

appSettings is located near the end of the file. If the error is still occurring increase the value 10000

Wednesday, November 14, 2012

MDS Missing attribute


Tag
Master Data Services

I had an issue where the subscription view would show all the attributes but when trying to edit the entity in Explorer or System Administration the attribute would not appear.
So started looking at mdm.tblAttribute table and there it was. So then I looked in mdm.viw_SYSTEM_SCHEMA_ATTRIBUTES and it was missing


SELECT
*
FROM
mdm.tblModel tMod  
JOIN mdm.tblEntity tEnt ON tMod.ID = tEnt.Model_ID  
JOIN mdm.tblAttribute tAtt ON tEnt.ID = tAtt.Entity_ID  
JOIN  mdm.tblEntityMemberType tMemberType ON tAtt.MemberType_ID = tMemberType.ID
JOIN mdm.tblList tAttributeType ON tAttributeType.ListCode = N'lstAttributeType' AND tAtt.AttributeType_ID = tAttributeType.OptionID
JOIN mdm.tblList tDataType ON tDataType.ListCode = N'lstDataType' AND tAtt.DataType_ID = tDataType.OptionID
--JOIN mdm.tblUser usrE ON tAtt.EnterUserID = usrE.ID
--JOIN mdm.tblUser usrL ON tAtt.LastChgUserID = usrL.ID
LEFT OUTER JOIN mdm.tblList tDataMask ON tDataMask.ListCode = N'lstInputMask' AND tAtt.InputMask_ID = tDataMask.OptionID AND tAtt.DataType_ID = tDataMask.Group_ID
LEFT OUTER JOIN mdm.tblEntity tDBAEnt ON tAtt.DomainEntity_ID = tDBAEnt.ID

It turns out I had DELETED all the users from the mdm.tblUser table except for user ID 1. Problem is viw_SYSTEM_SCHEMA_ATTRIBUTES does an INNER JOIN with the tblUser table.

Run the following to check if there are any issues.


SELECT * FROM mdm.tblEntity WHERE
EnterUserID <> 1
OR LastChgUserID <> 1

SELECT * FROM mdm.tblAttribute WHERE
EnterUserID <> 1
OR LastChgUserID <> 1

UPDATE mdm.tblAttribute SET EnterUserID = 1, LastChgUserID = 1 WHERE EnterUserID <> 1 OR LastChgUserID <> 1


Thursday, October 11, 2012

MDS Master Data Services 2012 Rename Entity Staging Table


DECLARE @StagingTable NVARCHAR(100) = 'StagingTableOldName'
DECLARE @NewStagingTable NVARCHAR(100) = 'StagingTableNewName'
DECLARE @EntityID INT

DECLARE db_cursor CURSOR FOR
SELECT e.ID, e.StagingBase, @NewStagingTable
  FROM [mdm].[tblEntity] e
  INNER JOIN mdm.tblModel m ON e.Model_ID = m.ID
  WHERE m.Name = 'MTN'
  AND e.StagingBase = @StagingTable
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @EntityID, @StagingTable, @NewStagingTable
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT '---- ' + @StagingTable
PRINT 'UPDATE mdm.tblEntity SET StagingBase = ' + QUOTENAME(@NewStagingTable, '''') + ' WHERE ID = ' + CAST(@EntityID AS NVARCHAR(10))
PRINT 'DROP PROC stg.udp_' + @StagingTable + '_Leaf'
PRINT 'DROP VIEW stg.viw_' + @StagingTable + '_MemberErrorDetails'
 
PRINT 'EXEC sp_rename ' + QUOTENAME('stg.' + @StagingTable + '_Leaf', '''') + ', ' + QUOTENAME(@NewStagingTable + '_Leaf', '''')
PRINT 'EXEC sp_rename ' + QUOTENAME('stg.' + @NewStagingTable + '_Leaf.pk_' + @StagingTable+ '_Leaf', '''') + ', ' + QUOTENAME('pk_' + @NewStagingTable + '_Leaf', '''')
PRINT 'EXEC sp_rename ' + QUOTENAME('stg.ck_' + @StagingTable + '_Leaf_ImportType', '''') + ', ' + QUOTENAME('ck_' + @NewStagingTable + '_Leaf_ImportType', '''')
PRINT 'EXEC sp_rename ' + QUOTENAME('stg.ck_' + @StagingTable + '_Leaf_ImportStatus_ID', '''') + ', ' + QUOTENAME('ck_' + @NewStagingTable + '_Leaf_ImportStatus_ID', '''')
PRINT 'EXEC sp_rename ' + QUOTENAME('stg.' + @NewStagingTable + '_Leaf.ix_' + @StagingTable + '_Leaf_Batch_ID', '''') + ', ' + QUOTENAME('ix_' + @NewStagingTable + '_Leaf_Batch_ID', '''')
PRINT 'EXEC sp_rename ' + QUOTENAME('stg.' + @NewStagingTable + '_Leaf.ix_' + @StagingTable + '_Leaf_BatchTag', '''') + ', ' + QUOTENAME('ix_' + @NewStagingTable + '_Leaf_BatchTag', '''')

PRINT 'EXEC sp_rename ' + QUOTENAME('stg.df_' + @StagingTable + '_Leaf_ImportStatus_ID', '''') + ', ' + QUOTENAME('df_' + @NewStagingTable + '_Leaf_ImportStatus_ID', '''')
PRINT 'EXEC mdm.udpEntityStagingCreateLeafStoredProcedure ' + CAST(@EntityID AS NVARCHAR(10))
PRINT 'EXEC mdm.udpCreateEntityStagingErrorDetailViews ' + CAST(@EntityID AS NVARCHAR(10))
PRINT ''
FETCH NEXT FROM db_cursor INTO @EntityID, @StagingTable, @NewStagingTable
END
CLOSE db_cursor
DEALLOCATE db_cursor

Thursday, August 9, 2012

MDS Checking Users Security Settings

Hi,

Here are some sql scripts that you can run to check the security settings of a user in MDS (Master Data Services).

-------------------------------------------------------------------------------      
-- Model User Security
-------------------------------------------------------------------------------
SELECT * FROM mdm.udfSecurityUserModelList(5) ACL
INNER JOIN mdm.viw_SYSTEM_SCHEMA_MODEL vModel ON ACL.ID = vModel.ID
INNER JOIN mdm.tblSecurityPrivilege tPriv ON tPriv.ID = acl.Privilege_ID
-------------------------------------------------------------------------------      
-- Entity User Security
-------------------------------------------------------------------------------
SELECT vEnt.Model_ID,vEnt.Model_Name,
acl.ID AS 'Entity_ID', vEnt.Name AS 'Entity_Name', tPriv.Code
FROM    mdm.udfSecurityUserEntityList(5, NULL) acl
INNER JOIN mdm.viw_SYSTEM_SCHEMA_ENTITY vEnt ON  acl.ID = vEnt.ID 
INNER JOIN mdm.tblSecurityPrivilege tPriv ON tPriv.ID = acl.Privilege_ID
ORDER BY vEnt.Model_ID, vEnt.Name
-------------------------------------------------------------------------------      
-- Attribute Group User Security
-------------------------------------------------------------------------------
SELECT * 
FROM    mdm.udfSecurityUserAttributeGroupList(5, 4,149,1) acl
INNER JOIN mdm.viw_SYSTEM_SCHEMA_ATTRIBUTEGROUPS vAG ON  acl.ID = vAG.ID 
INNER JOIN mdm.tblSecurityPrivilege tPriv ON tPriv.ID = acl.Privilege_ID
ORDER BY vAG.Model_ID, vAG.Name
-------------------------------------------------------------------------------      
-- Attribute Group Attribute List User Security
-------------------------------------------------------------------------------
SELECT acl.USER_ID, acl.Model_ID, vAG.Model_Name, acl.Entity_ID,
vAG.Entity_Name, acl.Privilege_ID, tPriv.Code AS 'SecurityAttributeGroup_Code',
vAG.ID AS 'AttributeGroup_ID', vAG.Name AS 'AttributeGroup_Name',
vAGA.Attribute_ID,vAGA.Attribute_Name, tPrivA.Code AS 'SecurityAttribute_Code'
FROM mdm.udfSecurityUserAttributeGroupList(1, 4,149,1) acl
INNER JOIN mdm.tblSecurityPrivilege tPriv ON tPriv.ID = acl.Privilege_ID
INNER JOIN mdm.viw_SYSTEM_SCHEMA_ATTRIBUTEGROUPS vAG ON  acl.ID = vAG.ID 
INNER JOIN  mdm.viw_SYSTEM_SCHEMA_ATTRIBUTEGROUPS_ATTRIBUTES vAGA ON vAG.ID = vAGA.AttributeGroup_ID
INNER JOIN mdm.udfSecurityUserAttributeList(1, 4,149,1) acla ON acla.ID = vAGA.Attribute_ID
INNER JOIN mdm.tblSecurityPrivilege tPrivA ON tPrivA.ID = acla.Privilege_ID
ORDER BY vAG.Model_ID, vAG.Name

-------------------------------------------------------------------------------      
-- Attribute List User Security
-------------------------------------------------------------------------------
SELECT va.Model_ID, va.Model_Name, va.Entity_ID, va.Entity_Name,
va.Attribute_ID, va.Attribute_Name, tPrivA.Code AS 'Security_Code'
FROM mdm.udfSecurityUserAttributeList(5, 4,149,1) acla
INNER JOIN mdm.viw_SYSTEM_SCHEMA_ATTRIBUTES vA ON acla.ID = vA.Attribute_ID
INNER JOIN mdm.tblSecurityPrivilege tPrivA ON tPrivA.ID = acla.Privilege_ID
ORDER BY vA.Model_ID, vA.Entity_Name, vA.Attribute_Name

Saturday, May 26, 2012

MDS .net Assembly Error "The Microsoft SQL Server license has expired"


I was trying to get MDS assemblies going.

File Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.ObjectModel;
using Microsoft.MasterDataServices.Deployment;
using Microsoft.MasterDataServices.Services.DataContracts;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //Reads a model's metadata, business rules, and master data
                ModelReader reader = new ModelReader();

                Console.WriteLine(reader.CurrentUser.DisplayName);
                Console.WriteLine("Models:");
                Collection<identifier> models = reader.GetModels();
                foreach (Identifier modelId in models)
                {
                    Console.WriteLine(modelId.Name);
                }
            }
            catch(System.Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);

            }
            Console.ReadKey();
        }
    }
}

App.Config

<configuration>
    <configsections>
    </configsections>
    <connectionstrings>
        <add connectionstring="Data Source=localhost;Initial Catalog=MDS_2012;Integrated Security=True" name="defaultMdsConnection" providername="System.Data.SqlClient">
    </add></connectionstrings>
</configuration>

referencing the following assemblies from
C:\Program Files\Microsoft SQL Server\110\Master Data Services\WebApplication\bin
Microsoft.MasterDataServices.Core
Microsoft.MasterDataServices.Deployment
Microsoft.MasterDataServices.Services
Microsoft.MasterDataServices.Services.Contracts

When running the app I get the following error:
Olof Szymczak
Models:
Error: The Microsoft SQL Server license has expired.


When using reflector, I find that the following method throws the error
File: Services.cs
Namespace: namespace Microsoft.MasterDataServices.Services
Method:
private static void CheckExpiration()
        {
            if (isExpired)
            {
                Microsoft.MasterDataServices.Core.Log.Write(LogMessageType.Error, "Evaluation period has expired.");
                EditionExpiredMessage detail = new EditionExpiredMessage();
                FaultException<editionexpiredmessage> exception = new FaultException<editionexpiredmessage>(detail, ErrorStrings.EvaluationExpired);
                throw exception;
            }
        }

It looks like isExpired is set to true. So I looked for the method that is setting isExpired. Drilling in that method I find:
File: Utility.cs
Namespace: Microsoft.MasterDataServices.Core.BusinessEntities
Method: private static QuerySkuValue LoadQuerySkuValueMethod()
in the method it is trying to load a dll C:\Program Files\Microsoft SQL Server\110\Shared\sqlboot.dll
                    zero = LoadLibraryW(dllname); //this fails to load the dll

Checked the location and the dll exists.

Note if I set isExpired = false while debugging the code. I get the correct results.

Eventually I found the answer after downloading http://archive.msdn.microsoft.com/ModelDApiSample, modifing it to point to the MDS 2012 assemblies and reconfiguring the config file. I run it and it worked, I was going WTF. So I checked what was wrong with my project settings, the answer x86, the project.Build.Platform target has to be set to either x64 or Any CPU.

All I can say is what a great way of telling you, that you have compiled the code for the wrong platform by returning an error of "The Microsoft SQL Server license has expired".

Friday, April 27, 2012

Install MDS on the Extranet

Hi,
I had to install MDS portal on the extranet (DMZ) and MDS database on the intranet. Here are some of the issues that I encountered.

Setup

DomainA (Intranet/Internal) ServerA SqlServer 2008 R2/2012
Firewall Firewall rule to let sql connection through. No Federated Domain
DomainB (Extranet/DMZ) ServerB IIS 7.5 make sure that IIS and WCF is installed correctly

Creating the database

Since I can't use Current User - Integrated Security I have to switch to SQL Server Account. Make sure that you create a sql login user with sufficient rights to create the database.

Creating Website

Everything works fine until you try to connect the database to the portal. You will get the following error:
Service Account Failure User or Role '(null)' does not exist in this database.
No problem you have to go the web.config file and add the settings manually. In this example I have added 2 sites dev and test
...
...    <masterDataServices>
        <instance virtualPath="" siteName="MDS_MTN_DEV" connectionName="MDS1" serviceName="MDS1" />
        <instance virtualPath="" siteName="MDS_MTN_TEST" connectionName="MDS2" serviceName="MDS2" />
    </masterDataServices>
    <connectionStrings>
        <add name="MDS1" connectionString="Data Source=[ServerNameOrServerIP];Initial Catalog=mds;User Id=[username];Password=[password];Connect Timeout=60" />
        <add name="MDS2" connectionString="Data Source=[ServerNameOrServerIP];Initial Catalog=mds_test;User Id=[username];Password=[password];Connect Timeout=60" />
    </connectionStrings>
...
...    
    <service behaviorConfiguration="mdsWsHttpBehavior" name="MDS1">
        <endpoint binding="wsHttpBinding" bindingConfiguration="mdsWsHttpBinding"
         bindingNamespace="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09"
         contract="Microsoft.MasterDataServices.Services.ServiceContracts.IService" />
        <endpoint address="bhb" binding="basicHttpBinding" bindingConfiguration="mdsBasicHttpBinding"
         bindingNamespace="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09"
         contract="Microsoft.MasterDataServices.Services.ServiceContracts.IService" />
       </service>
       <service behaviorConfiguration="mdsWsHttpBehavior" name="MDS2">
        <endpoint binding="wsHttpBinding" bindingConfiguration="mdsWsHttpBinding"
         bindingNamespace="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09"
         contract="Microsoft.MasterDataServices.Services.ServiceContracts.IService" />
        <endpoint address="bhb" binding="basicHttpBinding" bindingConfiguration="mdsBasicHttpBinding"
         bindingNamespace="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09"
         contract="Microsoft.MasterDataServices.Services.ServiceContracts.IService" />
       </service>
...
...
If you close and reopen Master Data Services Configuration Manager and go the website you will see that the website is now connected to the database.

Testing the MDS Portal

When viewing an entity in explorer you may get the following errors:
IE8 Error Message [HttpWebRequest_WebException_RemoteServer] Arguments: NotFound Debugging resource strings are unavaialble. Often the key and argumetns provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/linkid=1066638&Version5.0.61118.08&File=System.Windows.dll&Key=HttpWebRequest_WebException_RemoteServer
IE9 The remote server returned an error: NotFound.

Testing the MDS Service

Check Authorization on the Portal and Service in IIS Portal – Windows Authentication Enabled Service – Anonymous Authentication Enabled and Windows Authentication Enabled You may need to do an IISRESET. http://localhost/service/service.svc
Error Message for Anonymous Authentication not enabled Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.  Error Message for Windows Authentication not enabled Security settings for this service require Windows Authentication but it is not enabled for the IIS application that hosts this service.
Error Message: The HttpsGetEnabled property of ServiceMetadataBehavior is set to true and the HttpsGetUrl property is a relative address, but there is no https base address.  Either supply an https base address or set HttpsGetUrl to an absolute address.
Change the web.config file to the following if only using http httpsGetEnabled="false"
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
After all that it works!!!

Saturday, March 31, 2012

MDSModelDeploy.exe Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.


I was trying to automate the creation and deployment of my MDS model and came across the following issue.

If you try to run the following powershell command

invoke-command -computername Servername -scriptblock {& 'C:\Program Files\Microsoft SQL Server\110\Master Data Services\Configuration\MDSModelDeploy.exe' createpackage -model TestModel  -package c:\Data\LocalBackup\TestModelackage.pkg -version VERSION_1 -service MDS2 -includedata}

you get the following error
Creating a package for model MTN
MDSModelDeploy operation failed. Elapsed time: 00:00:06.4551044
Error:
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

I enabled trace on MDSModelDeploy

Error Log
MDS Information: 0 : Attempting to execute command: MDSModelDeploy createpackage -model TestModel -package c:\Data\LocalBackup\TestModelackage.pkg -version VERSION_1 -service MDS2 -includedata
    DateTime=2012-03-31T10:35:02.3896659Z
MDS Error: 0 : Service started successfully,  Assembly version: 11.0.0.0, file version: 11.0.2100.60 ((SQL11_RTM).120210-1917 )
    DateTime=2012-03-31T10:35:10.6863285Z
MDS Error: 0 : ApiContractVersion: 5102
    DateTime=2012-03-31T10:35:10.6863285Z
MDS Start: 1 : Service.InitializeExpirationStatus
    DateTime=2012-03-31T10:35:10.6863285Z
MDS Information: 0 : Evaluation period days remaining code: 0
    DateTime=2012-03-31T10:35:10.7488269Z
MDS Stop: 2 : Service.InitializeExpirationStatus
    DateTime=2012-03-31T10:35:10.7488269Z
MDS Start: 1 : Deployment: getting list of models
    DateTime=2012-03-31T10:35:10.7644515Z
MDS Start: 1 :
                  Begin operation: ExecuteRequest
                  Host info:       Microsoft.MasterDataServices.Core.ExplicitHostContext
                  User Name:       Domain\username
                  Time:            03/31/2012 21:35:10
    DateTime=2012-03-31T10:35:10.9050729Z
MDS Verbose: 0 : Request message:
<MetadataGetRequest xmlns="http://schemas.datacontract.org/2004/07/Microsoft.MasterDataServices.Services.MessageContracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <International i:nil="true" xmlns:a="http://www.w3.org/2005/09/ws-i18n" />
  <ResultOptions xmlns:a="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09">
    <a:Models>Identifiers</a:Models>
  </ResultOptions>
  <SearchCriteria xmlns:a="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09">
    <a:AttributeGroups />
    <a:Attributes />
    <a:DerivedHierarchies />
    <a:DerivedHierarchyLevels />
    <a:Entities />
    <a:ExplicitHierarchies />
    <a:MemberTypes />
    <a:Models />
    <a:VersionFlags />
    <a:Versions />
  </SearchCriteria>
</MetadataGetRequest>
    DateTime=2012-03-31T10:35:11.0613189Z
MDS Start: 1 : RequestContext.InitializeRequestContext
    DateTime=2012-03-31T10:35:11.0613189Z
MDS Start: 1 : RequestContext.InitializeDatabaseContext
    DateTime=2012-03-31T10:35:11.0613189Z
MDS Stop: 2 :
                  End  operation: MetadataGet
                  Host info:       Microsoft.MasterDataServices.Core.ExplicitHostContext
                  User Name:       [Domain]\[Username]
                  Time:            03/31/2012 21:35:11
    DateTime=2012-03-31T10:35:11.2956879Z
MDS Verbose: 0 : Response message:
<MetadataGetResponse xmlns="http://schemas.datacontract.org/2004/07/Microsoft.MasterDataServices.Services.MessageContracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <OperationResult xmlns:a="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09">
    <a:Errors />
    <a:RequestId>d8cedd0f-34cd-4b43-b43b-e0fd860bb44d</a:RequestId>
  </OperationResult>
  <Metadata xmlns:a="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09">
    <a:AttributeGroups />
    <a:Attributes />
    <a:DerivedHierarchies />
    <a:DerivedHierarchyLevels />
    <a:Entities />
    <a:ExplicitHierarchies />
    <a:MemberTypes />
    <a:Models />
    <a:VersionFlags />
    <a:Versions />
  </Metadata>
</MetadataGetResponse>
    DateTime=2012-03-31T10:35:11.4206847Z
MDS Error: 0 :
    DateTime=2012-03-31T10:35:11.4206847Z
MDS Error: 0 : MDSModelDeploy operation failed. Elapsed time: 00:00:09.1523012
    DateTime=2012-03-31T10:35:11.4206847Z
MDS Error: 0 : Error:
    DateTime=2012-03-31T10:35:11.4206847Z
MDS Error: 0 : System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
   at Microsoft.MasterDataServices.Core.DataAccess.DbHelper.ExecuteNonQueryHandlingTransportError(SqlCommand sqlCommand)
   at Microsoft.MasterDataServices.Core.DataAccess.DbHelper.GetTimeout(String settingName)
   at Microsoft.MasterDataServices.Core.DataAccess.DbHelper.SetConnection(String connectionString)
   at Microsoft.MasterDataServices.Core.BusinessEntities.RequestContext.InitializeDatabaseContext()
   at Microsoft.MasterDataServices.Core.BusinessEntities.RequestContext.InitializeRequestContext(HostContext hostContext)
   at Microsoft.MasterDataServices.Services.Service.MetadataGet(MetadataGetRequest request)
   at Microsoft.MasterDataServices.WebUI.ServiceAdapter.ExecuteRequest[TRequestType,TResponseType](MdmServiceOperation`2 operation, TRequestType request)
   at Microsoft.MasterDataServices.WebUI.ServiceAdapter.DoMetadataGet(MetadataSearchCriteria searchCriteria, MetadataResultOptions resultOptions)
   at Microsoft.MasterDataServices.Deployment.ModelReader.GetModels(Boolean isAdminOnly)
   at Microsoft.MasterDataServices.Deployment.Utility.ModelDeploy.CreatePackage(String serviceName, String packageFile, String modelName, String versionName, Boolean includeData)
   at Microsoft.MasterDataServices.Deployment.Utility.ModelDeploy.Main(String[] args)
    DateTime=2012-03-31T10:35:11.4206847Z


After using reflector I managed to find the code that is causing the issue
private void InitializeRequestContext(HostContext hostContext)
{
    Log.WriteStart("RequestContext.InitializeRequestContext");
    if (hostContext == null)
    {
        throw new ArgumentNullException("hostContext");
    }
    this.HostContext = hostContext;
    this.InitializeDatabaseContext();
    this.InitializeCurrentUser();
    Log.WriteStop("RequestContext.InitializeRequestContext");
}
Not sure if calling InitializeCurrentUser before InitializeDatabaseContext will fix the problem. As I didn’t have to time to decompile all the MDS code and try to get it to compile.

Work around
Is to set the connection string to sql login instead of Integrated Security
from        <add name="MDS2" connectionString="Data Source=servername;Initial Catalog=database;Integrated Security=True;Connect Timeout=60" />
to            <add name="MDS2" connectionString="Data Source=servername;Initial Catalog=database;User Id=sqlloginuser;Password=password;Connect Timeout=60" />


To test that winrm is working correctly run the following command
invoke-command -computername yourserver -scriptblock {& 'C:\Program Files\Microsoft SQL Server\110\Master Data Services\Configuration\MDSModelDeploy.exe' listservices}
Result
MDS services (Service, Website, Virtual Path):
MDS1, Website1_DEV,
MDS2, Website2_DEV,

MDSModelDeploy operation completed successfully. Elapsed time: 00:00:06.7047133

Wednesday, March 14, 2012

MDS (Master Data Services) SQL 2012 installing on SQL 2008 R2

MDS (Master Data Services) SQL 2012 is out with new enhancements to make development a lot easier. The issue is, is business ready to move to SQL 2012... So I took a shot and tried installing MDS SQL 2012 on SQL 2008 R2 instance.
Steps
1. install MDS SQL 2012 from ISO
2.Run Microsoft SQL Server 2012\Master Data Services\Master Data Services Configuration Manager.exe
3. Create new database point to SQL 2008 R2 instance.
4. Create new Web page

Everything run smoothly and portal came up.

http://msdn.microsoft.com/en-us/library/gg488708(v=sql.110).aspx#noengine

Thursday, March 8, 2012

Master Data Services (MDS) Clean Model of Carriage Return and New line


DECLARE @sqlquery NVARCHAR(4000)
DECLARE RemoveCr CURSOR FOR
SELECT DISTINCT --m.Name, e.Name, e.EntityTable, a.DisplayName,a.TableColumn, e.*,
'UPDATE mdm.' + e.EntityTable + ' SET ' + a.TableColumn + ' = SUBSTRING(' + a.TableColumn + ', 0, CHARINDEX ( CHAR(13), ' + a.TableColumn + ' ) ) WHERE ' + a.TableColumn + ' LIKE ''%'' + CHAR(13) + CHAR(10)+ ''%'''
--'SELECT ' + a.TableColumn + ' FROM mdm.' + e.EntityTable + ' WHERE ' + a.TableColumn + ' LIKE ''%'' + CHAR(13) + CHAR(10)+ ''%'''
FROM mdm.tblEntity e
INNER JOIN mdm.tblModel m ON e.Model_ID = m.ID
INNER JOIN mdm.tblModelVersion mv ON m.ID = mv.Model_ID
INNER JOIN mdm.tblAttribute a ON a.Entity_ID = e.ID
INNER JOIN mdm.tblList lAtt ON a.AttributeType_ID = lAtt.OptionID AND lAtt.ListCode = 'lstAttributeType'
INNER JOIN mdm.tblList lDat ON a.DataType_ID = lAtt.OptionID AND lDat.ListCode = 'lstDataType'
WHERE m.Name <> 'Metadata'
AND mv.Name = 'VERSION_1'
AND lAtt.ListOption <> 'System'
AND lDat.ListOption = 'Text'
AND IsBase = 0
OPEN RemoveCr
FETCH NEXT FROM RemoveCr INTO @sqlquery
WHILE (@@FETCH_STATUS = 0)
BEGIN
 EXEC(@sqlquery)
 FETCH NEXT FROM RemoveCr INTO @sqlquery
END
CLOSE RemoveCr

DEALLOCATE RemoveCr

Master Data Services (MDS) Moving Subscription Views


SET NOCOUNT ON
-------------------------------------------------------------------------------
-- Change the following variables
-------------------------------------------------------------------------------
DECLARE @Server VARCHAR(100) = 'SERVERNAME'
DECLARE @OrginalDatabase VARCHAR(100) = 'MDSDev'
DECLARE @DestinationDatabase VARCHAR(100) = 'MDSProd'
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
DECLARE @execQuery VARCHAR(1000) = 'SELECT * INTO ##Views FROM OPENROWSET(''SQLNCLI'', ''server=' + @Server + ';trusted_connection=yes'', ''set fmtonly off exec ' + @OrginalDatabase + '.[mdm].[udpSubscriptionViewGet]'')'
EXEC(@execQuery)

DECLARE @View_Name NVARCHAR(200)
DECLARE @Model_Name NVARCHAR(200)
DECLARE @Entity_Name NVARCHAR(200)
DECLARE @query NVARCHAR(4000)
DECLARE db_Cursor CURSOR FOR

SELECT View_Name, Model_Name, Entity_Name FROM ##Views
OPEN db_Cursor
FETCH NEXT FROM db_Cursor INTO @View_Name, @Model_Name, @Entity_Name
WHILE @@FETCH_STATUS = 0
BEGIN
SET @query = ''
SET @query = 'DECLARE @EntityName NVARCHAR(200) = ''' + @Entity_Name + '''' + CHAR(10)
SET @query = + @query + 'DECLARE @ModelName NVARCHAR(200) = ''' + @Model_Name + '''' + CHAR(10)
SET @query = + @query + 'DECLARE @Entity_ID int' + CHAR(10)
SET @query = + @query + 'DECLARE @Model_ID int' + CHAR(10)
SET @query = + @query + 'DECLARE @ModelVersion_ID int' + CHAR(10)
SET @query = + @query + 'DECLARE @ModelVersionFlag_ID int' + CHAR(10)
SET @query = + @query + 'DECLARE @Return_ID int' + CHAR(10)
SET @query = + @query + 'DECLARE @Return_MUID uniqueidentifier' + CHAR(10)
SET @query = + @query + CHAR(10)
SET @query = + @query + 'SELECT @Model_ID = m.id, @Entity_ID=e.ID, @ModelVersion_ID = mv.ID, @ModelVersionFlag_ID = mv.VersionFlag_ID FROM mdm.tblModel m' + CHAR(10)
SET @query = + @query + 'INNER JOIN mdm.tblEntity e ON m.ID = e.Model_ID' + CHAR(10)
SET @query = + @query + 'INNER JOIN mdm.tblModelVersion mv ON m.ID = mv.Model_ID' + CHAR(10)
SET @query = + @query + 'WHERE mv.Name = ''VERSION_1''' + CHAR(10)
SET @query = + @query + 'AND m.NAME = @ModelName' + CHAR(10)
SET @query = + @query + 'AND e.Name = @EntityName' + CHAR(10)
SET @query = + @query + CHAR(10)
SET @query = + @query + 'EXECUTE [' + @DestinationDatabase + '].[mdm].[udpSubscriptionViewSave]' + CHAR(10)
SET @query = + @query + '@SubscriptionView_ID=NULL' + CHAR(10)
SET @query = + @query + ',@Entity_ID = @Entity_ID' + CHAR(10)
SET @query = + @query + ',@Model_ID = @Model_ID' + CHAR(10)
SET @query = + @query + ',@DerivedHierarchy_ID = NULL' + CHAR(10)
SET @query = + @query + ',@ModelVersion_ID = @ModelVersion_ID ' + CHAR(10)
SET @query = + @query + ',@ModelVersionFlag_ID = @ModelVersionFlag_ID' + CHAR(10)
SET @query = + @query + ',@ViewFormat_ID = 1' + CHAR(10)
SET @query = + @query + ',@Levels = NULL' + CHAR(10)
SET @query = + @query + ',@SubscriptionViewName = ''' + @View_Name + '''' + CHAR(10)
SET @query = + @query + ',@Return_ID = @Return_ID OUTPUT' + CHAR(10)
SET @query = + @query + ',@Return_MUID = @Return_MUID OUTPUT' + CHAR(10)
SET @query = + @query + 'GO' + CHAR(10)
      PRINT @query
      FETCH NEXT FROM db_Cursor INTO @View_Name, @Model_Name, @Entity_Name

END
CLOSE db_Cursor
DEALLOCATE db_Cursor
DROP TABLE ##Views
GO

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