title: SQL Server Database Roles via SMO
body: <p>I am trying to add new roles to a SQL 2005 database via the SMO assemblies. The Roles.Add method just does not seem to add the new role. I have my user account set as securityadmin and sysadmin.</p>
  
  <p>Below is the code extract that I am trying to use to set the new role:
  [assuming d has been set to a database object]</p>
  
  <pre><code>        Dim dr As New DatabaseRole
          dr.Name = r
          dr.Parent = d
          dr.Owner = d.Name
          d.Roles.Add(dr)
  
          'Error here "&lt;role name = r&gt; does not exist in the current database."'
          dr.AddMember("dbo")
  </code></pre>