title: How to access OLEDB Connection Manager in SSIS script task
body: <p>I am new to SSIS script task, I tried the below code to run a sql query in SSIS script task but I am end up with an error.</p>
  
  <pre><code>ConnectionManager cm = Dts.Connections["oledb"]; 
  IDTSConnectionManagerDatabaseParameters100 cmParams = cm.InnerObject as IDTSConnectionManagerDatabaseParameters100; 
  OleDbConnection sqlConn = cmParams.GetConnectionForSchema() as OleDbConnection;
  </code></pre>
  
  <p>ErrorMessage: </p>
  
  <blockquote>
    <p>Unable to cast COM object of type 'System.__ComObject' to class type
    'System.Data.SqlClient.SqlConnection'.  Instances of types that
    represent COM components cannot be cast to types that do not represent
    COM components;  however they can be cast to interfaces as long as the
    underlying COM component supports QueryInterface calls for the IID of
    the interface</p>
  </blockquote>
  
  <p>I am trying to find DB Server name and try to assign the value to $Project::variable using Script task.</p>
  
  <p>Is there anyway I can do this. </p>
  
  <p>Thanks in advance.</p>