title: What is the most secure way to allow users to execute BCP export command from SQL?
body: <p>I am currently working in an environment where the ability to <strong>export</strong> a table <strong>programatically</strong> from within a hand-run SQL script would be of great help.  </p>
  
  <p>Performing the exports from script will be the first step towards running the entire process from within a stored procedure, therefore I have to be able to initiate the export from SQL.</p>
  
  <p>The organisation currently has the following configuration on most servers - </p>
  
  <ul>
  <li>SQL Server 2005 or 2008</li>
  <li>xp_cmdshell - <strong>disabled</strong></li>
  <li>CLR - <strong>enabled</strong></li>
  </ul>
  
  <p>Ultimately, I would like to be able to call a procedure passing the following parameters and have it perform the export.</p>
  
  <ul>
  <li>table name</li>
  <li>file path/name (on a network share)</li>
  <li>file format </li>
  </ul>
  
  <p>Currently BCP seems like a perfect option in terms of functionality but I am unable to invoke it via the command line due to xp_cmdshell being disabled.</p>
  
  <p>The organisation is quite small and happy work towards a secure solution and my impression so far is that they have a good level of control over their security.  They have made a blanket decision to disable xp_cmdshell but if I could present a safe way to allow use of it I think they would be pretty receptive. </p>
  
  <p>In my research I've come across both the <strong>'EXECUTE AS'</strong> functionality as well as signing procedures with <strong>certificates</strong>, but still cant work out if either approach can help me achieve what I want.</p>
  
  <p>Also, if you have another solution that allows me to achieve the same end-result I'm all ears!</p>