1

I am trying to use powershell for importing a resource file in Business Data Catalog but I keep getting the following error

Import-SPBusinessDataCatalogModel : The root element of a valid
Metadata package must be 'Model' in namespace
'http://schemas.microsoft.com/windows/2007/BusinessDataCatalog'. The root in the given package is 'Model' in namespace'http://schemas.microsoft.com/windows/2007/BusinessDataCatalog/Resources'.

Error was encountered at or just before Line: '2' and Position: '2'. At M:\PowerShell\ImportModel.ps1:13 char:35
+  Import-SPBusinessDataCatalogModel <<<<  -Path $file.FullName -Identity $bdc -force -ModelsIncluded -PropertiesIncluded -Verbose
+ CategoryInfo          : InvalidData: (Microsoft.Share...alogModelCmdlet:SPImportSPBusinessDataCatalogModelCmdlet)
[Impo     rt-SPBusinessDataCatalogModel], PackageFormatException
+ FullyQualifiedErrorId : Microsoft.SharePoint.BusinessData.SharedService.SPImportSPBusinessDataCatalogModelCmdlet

When I manualy import the resource file everything is ok.

This is the resource file i Use

<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<Model xmlns="http://schemas.microsoft.com/windows/2007/BusinessDataCatalog/Resources" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="CZ.Sharepoint.BCS.Correspondentie.Zorg">
  <LobSystems>
    <LobSystem Name="Correspondentie">
      <Properties>
        <Property Name="WildcardCharacter" Type="System.String">%</Property>
      </Properties>
      <LobSystemInstances>
        <LobSystemInstance Name="Correspondentie">
          <Properties>
            <Property Name="AuthenticationMode" Type="System.String">PassThrough</Property>
            <Property Name="DatabaseAccessProvider" Type="System.String">SqlServer</Property>
            <Property Name="RdbConnection Data Source" Type="System.String">TSTSQL10</Property>
            <Property Name="RdbConnection Initial Catalog" Type="System.String">PRD_Correspondentie</Property>
            <Property Name="RdbConnection Integrated Security" Type="System.String">SSPI</Property>
            <Property Name="RdbConnection Pooling" Type="System.String">True</Property>
            <Property Name="ShowInSearchUI" Type="System.String"></Property>
          </Properties>
        </LobSystemInstance>
      </LobSystemInstances>
    </LobSystem>
  </LobSystems>
</Model>

And the powershell script

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$serviceContext = "http://localhost/"

$bdc = Get-SPBusinessDataCatalogMetadataObject -BdcObjectType Catalog -ServiceContext $serviceContext
$pathtobdcmfiles = Get-Location
$importFiles = Get-Childitem -path $pathtobdcmfiles | Where {$_.extension -eq ".bdcr" -and $_.basename -ne "catalog"}

foreach ($file in $importFiles) {
 Import-SPBusinessDataCatalogModel -Path $file.FullName -Identity $bdc -force -ModelsIncluded -PropertiesIncluded -Verbose
 write-host $file.fullname
 }

3 Answers 3

1

The following script worked for me. Im just importing properties but you could modify it to account for any other content contained in the resource file.

#imports the BCS resource file 
function ConfigureBCSModel([string]$path)
{
    $results = $null;

    # open the settings file
    $data = Get-Content $path

    # link to the central admin web context
    $centralAdmin = (Get-spwebapplication -includecentraladministration | where {$_.IsAdministrationWebApplication} | select Url -First 1).Url

    #connect to the bdc service
    $bdc = Get-SPBusinessDataCatalogMetadataObject -BdcObjectType Catalog -ServiceContext $centralAdmin

    #import the package
    $bdc.ImportPackage($data, [ref]$results, [Microsoft.SharePoint.BusinessData.Parser.PackageContents]::Properties)

    # write out the import setting values
    foreach($result in $results)
    {
        Write-Host "Setting Import message: " $result;
    }  
}
0

The error message seems to have the answer. Have you tried changing your xmlns?

xmlns="http://schemas.microsoft.com/windows/2007/BusinessDataCatalog/Resources"

to

xmlns="http://schemas.microsoft.com/windows/2007/BusinessDataCatalog"

1
  • If i change that line i get the following error: Missing LobSystem (External System) Type information during Model import. Does the XML tha t you are importing conform to the Resource schema instead of the Model schema?
    – Remko
    Commented Oct 27, 2011 at 14:10
0

MLF Answer is correct. (Can't use comments yet.) You get the next error because you haven't specified the Type attribute in your LobSystem element.

Here is an example http://msdn.microsoft.com/en-us/library/ff817559.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.