The answer to this depends somewhat on which connection manager you use to connect to the database, however the general approach is the same:
, SSIS.
ADO.NET :
public override DTSExecResult Validate(
Connections connections, VariableDispenser variableDispenser,
IDTSComponentEvents componentEvents, IDTSLogging log)
{
if(!connections.Contains("YourConnection"))
{
componentEvents.FireError(0, "CustomTask",
"Invalid connection manager.", "", 0);
return DTSExecResult.Failure;
}
return DTSExecResult.Success;
}
public override DTSExecResult Execute(Connections connections,
VariableDispenser variableDispenser, IDTSComponentEvents componentEvents,
IDTSLogging log, object transaction)
{
ConnectionManager cm = connections["YourConnection"];
try
{
SqlConnection connection
= cm.AcqureConnection(transaction) as SqlConnection;
if(connection == null)
{
componentEvents.FireError(0, "CustomTask",
"Failed to acquire ADO.NET connection.", "", 0);
Return DTSExecResult.Failure;
}
}
catch(Exception ex)
{
componentEvents.FireError(0, "CustomTask",
ex.Message, "", 0);
Return DTSExecResult.Failure;
}
}
, , , .
!