SQLtoExcel
SQLtoExcel copied to clipboard
SQLtoExcel can't handle sql script files with multiple result sets
Executing a stored proc with multiple result sets throws a duplicate exception.
suggested fix:
// Program.cs
dtCopy.TableName = GetTableName(fi.Name.Replace(fi.Extension, ""));
...
private static HashSet<string> _sheetnames = new HashSet<string>();
private static string GetTableName(string name, int duplicate = 0)
{
name = name.Substring(0, name.Length > 31 ? 31 : name.Length);
var newname = duplicate == 0 ? name : $"{name}({duplicate})";
if (_sheetnames.Contains(newname))
{
name = name.Substring(0, name.Length > 28 ? 28 : name.Length); // up to 9 duplicates
return GetTableName(name, ++duplicate);
}
_sheetnames.Add(newname);
return newname;
}