Skip to content

Instantly share code, notes, and snippets.

@matt40k
Created June 9, 2016 20:15
Show Gist options
  • Save matt40k/191f8e28c3bc68df5d6340d9a30f9859 to your computer and use it in GitHub Desktop.
Save matt40k/191f8e28c3bc68df5d6340d9a30f9859 to your computer and use it in GitHub Desktop.
SSIS - Fires the connection strings into information messages - from http://sqlblog.com/blogs/jamie_thomson/archive/2011/10/25/verify-a-connection-before-using-it-ssis.aspx
public void Main()
{
bool failure = false;
bool fireAgain = true;
foreach (var ConnMgr in Dts.Connections)
{
Dts.Events.FireInformation(1, "", String.Format("ConnectionManager='{0}', ConnectionString='{1}'",
ConnMgr.Name, ConnMgr.ConnectionString), "", 0, ref fireAgain);
try
{
ConnMgr.AcquireConnection(null);
Dts.Events.FireInformation(1, "", String.Format("Connection acquired successfully on '{0}'",
ConnMgr.Name), "", 0, ref fireAgain);
}
catch (Exception ex)
{
Dts.Events.FireError(-1, "", String.Format("Failed to acquire connection to '{0}'. Error Message='{1}'",
ConnMgr.Name, ex.Message),
"", 0);
failure = true;
}
}
if (failure)
Dts.TaskResult = (int)ScriptResults.Failure;
else
Dts.TaskResult = (int)ScriptResults.Success;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment