title: Call dll function from sql stored procedure using the current connection
body: <p>Can I call a dll from a stored procedure using the open connection?</p>
  
  <p>I have a dll that gets data from SQL Server and I don't want to open a new connection when I call it from the stored procedure.</p>
  
  <p>Thank you</p>
  
  <p>Here is an exemple</p>
  
  <pre><code>public class Class1
  {
      public static SqlString GetName(SqlString str)
      {
          SqlCommand cmd = new SqlCommand(str.ToString());
          cmd.CommandType = System.Data.CommandType.Text;
  
          string name = cmd.ExecuteScalar().ToString();
          return name;
      }
  }
  </code></pre>
  
  <p>and this is the SQL code</p>
  
  <pre><code>CREATE FUNCTION fn_TestConnection
  (
      @str nvarchar(255)
  )
  RETURNS nvarchar(max)
  AS EXTERNAL NAME TestConnection.[TestConnection.Class1].GetName
  GO
  
  SELECT dbo.fn_TestConnection('SELECT FName FROM Clients WHERE Id = 1' )
  </code></pre>