title: Database backup via SMO (SQL Server Management Objects) in C#
body: <p>I need to backup database (using SQL Server 2008 R2). Size of db is about 100 GB so I want backup content only of important tables (containing settings) and of course object of all tables, views, triggers etc.</p>
  
  <p>For example:</p>
  
  <ul>
  <li>db: <code>Products</code>  </li>
  <li>tables: <code>Food, Clothes, Cars</code></li>
  </ul>
  
  <p>There is too much cars in <code>Cars</code>, so I will only backup table definition (<code>CREATE TABLE ...</code>) and complete <code>Food</code> and <code>Clothes</code> (including its content).</p>
  
  <p>Advise me the best solution, please. I will probably use SMO (if no better solution). Should I use <code>Backup</code> class? Or <code>Scripter</code> class? Or another (if there is any)? Which class can handle my requirements?</p>
  
  <p>I want backup these files to <code>*.sql</code> files, one per table if possible.</p>
  
  <p>I would appreciate code sample. Written in answer or somewhere (post url), but be sure that external article has solution exactly for this kind of problem.</p>
  
  <p>You can use this part of code</p>
  
  <pre><code>ServerConnection connection = new ServerConnection("SERVER,1234", "User", "User1234");
  Server server = new Server(connection);
  Database database = server.Databases["DbToBackup"];
  </code></pre>