I’ve been working with a number of customers to implement SQL Server Master Data Services, and found some common requests from customers that require some custom code to implement.  Over the course of those engagements I wrote a set of utilities for MDS that are now published on CodePlex http://mdsutilities.codeplex.com.  The questions I kept getting were:

1) How do I import an entity model from SQL Server (or ERWin) into Master Data Services?

2) How do I load the entity model from a SQL table or an SSIS package?

3) How do I build a custom web UI for business users to edit master data?

4) How do I integrate master data into SharePoint Business Connectivity Services (BCS)?

The answers these questions were:

1) Manually

2) Write code to pivot your data to fit the Entity/Attribute/Value form of the MDS staging tables.

3) Write an ASP.NET web application using the MDS web service

4) Write simple wrapper web services in front of the MDS web service that BCS can consume.

Which led to me writing samples for all these scenarios and those samples are the CodePlex MDS Utilities project.  The components of the MDS Utilities project are the new answers to these questions:

1) Use the MdsModelImport.exe command line utility to import a SQL Server database schema.

2) Use the mds_staging database to generate entity-based staging views that front-end the MDS staging tables.

3) Write an ASP.NET web app using MdsDataSource control for no-code and low-code data binding to MDS model data.

4) Use the DataServiceGenerator or the DataServiceAdministration web page to generate CRUD web services for your model, and plug those in to SharePoint BCS.

I am going to walk through all four of these scenarios in a series of posts.  In this post we’ll just create a simple MDS model from the AdventureWorks sample database.

First download MdsModelImport.exe from the current project release http://mdsutilities.codeplex.com/releases, or download the source and built it.  It’s a .NET 4.0 project, so you’ll need .NET 4 to build and run it.  (Remember you don’t need Visual Studio 2010 to build a .NET project, you can just run C:\windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe.)

You can see the available command line arguments with -?

C:\projects\Codeplex\MDSUtilities\Output>MDSModelImport.exe -?
Usage: MDSModelImport

    [-?]                   Print this help guide.
    -Server:STRING         Source SQL Server
    -Database:STRING       Source Database Name
    -Model:STRING          Name of the MDS Model to create.  It must not exist.
    [-Schema:STRING]       Schema to use for import.  Default is all schemas.
    [-MDSEndpoint:STRING]  URL to MDS Web Service.  Default is in MDSModelImport.exe.config

So we want to create a model from AdventureWorks.  We’ll use just the HumanResources schema, and create a model called HumanResources.  Also we’ll specify the MDS web service endpoint address on the command line.  If you omit the MDSEndpoint argument, you need to configure the WCF connection information in the MDSModelImport.exe.config file. 

If the model name is in use you may need to delete the existing mode (MdsModelImport won’t delete it for you).  You delete a model by navigating to the System Administration/Manage/Models in the MDS UI, or jump to it here http://localhost/MDS/Admin/dimension.aspx?ACTION=LIST (assuming you are working on the MDS server and the web site is using the default name of ‘MDS’).  Just click on the model you want to delete to select it and hit the red X.


Then run MdsModelImport.exe from a command prompt, running as an account with administrative access to MDS and read access to the target database. 

C:\projects\Codeplex\MDSUtilities\Output>MDSModelImport.exe -server (local) -database AdventureWorks -schema HumanResources -model HumanResources -MDSEndpoint http://localhost/mds/Service/Service.svc
Source Server: (local)
Source Database: AdventureWorks
MDS Web Service Endpoint Url:
Importing HumanResources schema.

Model Created

After creating the model you’ll need to hit the ‘refresh’ link on the MDS home page for it to show up:


You can then explore the model in MDS, or delete the MDS model, make changes to the SQL schema and rerun the import tool.  The mapping from tables to entities is simple:  For each table an entity is created with the same name.  If you have prefixes or CAPS_AND_UNDERSCORES naming conventions in your database, you may want to create a database version with more readable names before importing.  Every entity in MDS is uniquely identified by an attribute called Code, and every entity also has a Name attribute, so the key structure on the tables doesn’t matter.  The import tool will simply create a scalar attribute for each column in your table, including key columns, but excluding columns that are part of a Foreign Key.  For each Foreign Key on your table a Domain Attribute is created. 

The resulting model is not a finished product and the MdsModelImport tool is not intended to keep your model in sync with a SQL Server database.  Rather it’s a “jump start” to get an initial draft of the MDS model design in place quickly, and save you from having to manually enter all the entities and attributes.  From that starting point you can add and remove entities and attributes, write business rules, implement security, etc.

In the next post I’ll show you how to easilly load data into this new model using a straight SQL INSERT, or a _simple_ SSIS package using the mds_staging database from the MDS Utilities.