title: SMO.Transfer: cannot convert type "database" to type "database"
body: <p>Here is a powershell script:</p>
  
  <pre><code>[string] $server   = "devserver\mssql";          # SQL Server Instance
  [string] $database = "ftg";      # Database with the tables to script out.
  [string] $folder   = "d:\FT\FTProject\";          # Path to export to
  [string] $SQLLogin = "Sa";
  [string] $SQLPass  = "Sa1234";
  
  # Reference to SMO
  [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO');
  
  Write-Output ((Get-Date -format yyyy-MM-dd_HH-mm-ss) + ": Started ...");
  
  $con = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($server, $SQLLogin, $SQLPass);
  $srv = New-Object Microsoft.SqlServer.Management.SMO.Server($con);
  $db = New-Object Microsoft.SqlServer.Management.SMO.Database($srv, $database);
  
  
  #Use SMO Transfer Class by specifying source database
  #you can specify properties you want either brought over or excluded, when the copy happens
  $ObjTransfer   = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Transfer;
  $ObjTransfer.Database = $db
  </code></pre>
  
  <p>At last line an error occurs: </p>
  
  <p>Exception setting "Database": "Cannot convert the "[ftg]" value of type "Microsoft.SqlServer.Management.Smo.Database" to type "Microsoft.SqlServer.Managem
  ent.Smo.Database"."
  At D:\FT\FTProject\Setup\transfer.ps1:31 char:1
  + $ObjTransfer.Database = [Microsoft.SqlServer.Management.SMO.Database] $db
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
      + FullyQualifiedErrorId : ExceptionWhenSetting</p>
  
  <p>I also tryed to set $db as follows:</p>
  
  <pre><code>$db = $srv.Databases[$database]
  </code></pre>
  
  <p>What is wrong?</p>