microsoft / sqltoolsservice

SQL Tools API service that provides SQL Server data management capabilities.
Other
441 stars 149 forks source link

Microsoft.SqlServer.Management.Smo including 2019 OPTIMIZE_FOR_SEQUENTIAL_KEY in 2017 db script #921

Open WayneHiller opened 4 years ago

WayneHiller commented 4 years ago

I am using Microsoft.SqlServer.Management.Smo Server and Transfer objects to export a "Create Database" script file from an existing database. I am running SQL Server Dev 2019. The database I am exporting (creating the script for) is 2017. The export is including the new 2019 only option OPTIMIZE_FOR_SEQUENTIAL_KEY on all create table statements. This means the script will fail when running on SQL Server 2017.

WayneHiller commented 4 years ago

I just tried setting the TargetServerVersion and it fixed the problem. transfer.Options.TargetServerVersion = SqlServerVersion.Version140; Shouldn't it set that by default to the version of the database?