Seems some people still use this!

May 30 at 1:00 PM
Edited Tue at 10:34 AM
Glad it's open source now as we bought the dll many years ago and it's an integral part of our products.

Every now and then we encounter an unexpected issue which I've managed to fix. The standard one is the incompatibility with later versions of SQL Server. This is documented elsewhere, but the general fix is to keep reusing the old 2008 ReverseEngine as the newer versions are generally backwards compatible.

Obviously fancy new features won't be supported, but we've not encountered any problems so far...

The ReverseEngine.cs is the main class that needs tweaking. In the 'CreateReverseEngine' method, just add in a check for each new serverVersion.Major to get by. I've been updating the SqlVersionEnum as well, but haven't done much more with it.

Code is as below:
   public static ReverseEngine CreateReverseEngine(SqlConnection sqlConnection, SqlTransaction sqlTransaction, ProgressCallback progress)
    {
        //Version serverVersion = ServerUtils.GetSqlServerVersion(sqlConnection, sqlTransaction);
        Version serverVersion = new Version(sqlConnection.ServerVersion);
        if (serverVersion.Major == 9)
        {
            return new ReverseEngine(sqlConnection, sqlTransaction, progress, SqlVersionEnum.Sql2005);
        }
        if (serverVersion.Major == 10)
        {
            return new ReverseEngineSql2008(sqlConnection, sqlTransaction, progress, SqlVersionEnum.Sql2008);
        }
        if (serverVersion.Major == 11)
        {
            return new ReverseEngineSql2008(sqlConnection, sqlTransaction, progress, SqlVersionEnum.Sql2012);
        }
        if (serverVersion.Major == 12)
        {
            return new ReverseEngineSql2008(sqlConnection, sqlTransaction, progress, SqlVersionEnum.Sql2014);
        }
        if (serverVersion.Major == 13)
        {
            return new ReverseEngineSql2008(sqlConnection, sqlTransaction, progress, SqlVersionEnum.Sql2016);
        }
        throw new ApplicationException("This applications supports Microsoft SQL Server 2005, 2008, 2012, 2014 and 2016 only.");
    }
The latest issue I encountered was it throwing an error about a User Defined Table Type that it said was unrecognised. I checked in the code and it looks to have been commented out / partially completed perhaps.

As part of the 'GetDataType' routine in ReverseEngine.cs, it does a check for UserDefinedTypes and CLRTypes. I just added in an identical loop but checking for 'TableTypeSql10' which seems to be the internal representation of User Defined Table Types.

This seems to have worked. Code is as below.

foreach (TableTypeSql10 type in database.Objects.GetElements<PerpetuumSoft.DataModel.MsSql.TableTypeSql10>())
                {
                    if (type.Schema.Name + "." + type.Name == typeSchemaName + "." + typeName)
                    {
                        dType = new DataType.UserTableType(type as TableTypeSql10);
                        existType = true;
                        break;
                    }
                }
Hope that helps somebody!

EDIT:

In addition, you need to add a couple of lines to FunctionBase.cs so that it knows if there's a dependency on a UserTableType parameter in a stored procedure / function... The extra two lines are the last two, with 'UserTableType' having been added.
internal IEnumerable<Element> GetLogicalDependensFromParameters()
{
  foreach (InParameter param in Parameters)
  {
    if (param.Type is DataType.Xml)
    {
      DataType.Xml type = param.Type as DataType.Xml;
      if (type.XmlSchemaCollection != null)
        yield return type.XmlSchemaCollection;
    }

    if (param.Type is DataType.UserType)
      yield return (param.Type as DataType.UserType).TypeReference;
    if (param.Type is DataType.UserCLRType)
      yield return (param.Type as DataType.UserCLRType).TypeReference;
   if (param.Type is DataType.UserTableType)
      yield return (param.Type as DataType.UserTableType).TypeReference;
  }
}