static internal SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion, Guid conId, Exception innerException = null)
{
Debug.Assert(null != errorCollection && errorCollection.Count > 0, "no errorCollection?");
StringBuilder message = new StringBuilder();
for (int i = 0; i < errorCollection.Count; i++)
{
if (i > 0)
{
message.Append(Environment.NewLine);
}
message.Append(errorCollection[i].Message);
}
if (innerException == null && errorCollection[0].Win32ErrorCode != 0 && errorCollection[0].Win32ErrorCode != -1)
{
innerException = new Win32Exception(errorCollection[0].Win32ErrorCode);
}
SqlException exception = new SqlException(message.ToString(), errorCollection, innerException, conId);
exception.Data.Add("HelpLink.ProdName", "Microsoft SQL Server");
if (!string.IsNullOrEmpty(serverVersion))
{
exception.Data.Add("HelpLink.ProdVer", serverVersion);
}
exception.Data.Add("HelpLink.EvtSrc", "MSSQLServer");
exception.Data.Add("HelpLink.EvtID", errorCollection[0].Number.ToString(CultureInfo.InvariantCulture));
exception.Data.Add("HelpLink.BaseHelpUrl", "http://go.microsoft.com/fwlink");
exception.Data.Add("HelpLink.LinkId", "20476");
return exception;
}