microsoft / DacFx

SQL Server database schema validation, deployment, and upgrade runtime. Enables declarative database development and database portability across SQL Server versions and environments.
https://aka.ms/sqlpackage-ref
MIT License
296 stars 16 forks source link

Export completes even if it fails to serialize elements to model.xml #310

Open llali opened 11 months ago

llali commented 11 months ago

Steps to Reproduce:

  1. Create a database with a procedure with a special character which will fail to serialize to xml (TODO: add a sample script for the procedure)
  2. Export the database to bacpac

Expected: export either successfully create the bacpac to fails and show a meaningful error for user Actual: export fails but it creates the bacpac and logs shows export completed successfully. user sees an error in the console:

Exporting data from database

Exporting data

*** Error exporting database:The surrogate pair (0xDBA4, 0x69) is invalid. A high surrogate character (0xD800 - 0xDBFF) must always be paired with a low surrogate character (0xDC00 - 0xDFFF).

Did this occur in prior versions? If not - which version(s) did it work in?

(DacFx/SqlPackage/SSMS/Azure Data Studio)

llali commented 11 months ago

there are two issues here. # 1 why serializing fails. # 2 if it fails, dacfx should not create the bacpac with missing origin.xml. for # 1 I was not able to repro the issue. the procedure user has include a � character which export successfully for me. It's possible the local or the machine is different for the user. for issue # 2 we need to catch the errors when serializing the model.xml and fail the operation. here's the stack trace `The surrogate pair (0xDBA4, 0x69) is invalid. A high surrogate character (0xD800 - 0xDBFF) must always be paired with a low surrogate character (0xDC00 - 0xDFFF). (System.Xml)

at System.Xml.XmlEncodedRawTextWriter.EncodeSurrogate(Char pSrc, Char pSrcEnd, Char* pDst) at System.Xml.XmlEncodedRawTextWriter.WriteCDataSection(String text) at System.Xml.XmlEncodedRawTextWriter.WriteCData(String text) at System.Xml.XmlEncodedRawTextWriterIndent.WriteCData(String text) at System.Xml.XmlWellFormedWriter.WriteCData(String text) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlSchemaModel.WriteScriptToXml(XmlWriter writer, String script) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlSchemaModel.SerializeExternalProperty(XmlWriter writer, ModelPropertyClass propertyClass, Object property) at Microsoft.Data.Tools.Schema.SchemaModel.DataSchemaModel.XmlSerializerInternal.WriteProperties(ModelPropertyContainerClass propertyContainerClass, IModelPropertyContainer propertyContainer) at Microsoft.Data.Tools.Schema.SchemaModel.DataSchemaModel.XmlSerializerInternal.WriteElement(IModelElement root) at Microsoft.Data.Tools.Schema.SchemaModel.DataSchemaModel.XmlSerializerInternal.WriteStore() at Microsoft.Data.Tools.Schema.SchemaModel.DataSchemaModel.Serialize(TextWriter output, IEnumerable1 annotationTypesToInclude, Boolean includePositions, UInt32 minimalSchemVersion) at Microsoft.Data.Tools.Schema.Sql.Build.DacUtilities.AddModelToSqlPackage(SqlPackage package, DataSchemaModel model, IEnumerable1 annotations, Nullable1 minModelVersion) at Microsoft.SqlServer.Dac.DacPackage.WritePackageContent(SqlPackage package, DataSchemaModel model, DacMetadata metadata, Nullable1 minModelVersion) at Microsoft.SqlServer.Dac.DacPackage.Save(Stream stream, DataSchemaModel model, DacMetadata metadata, Nullable1 minModelVersion) at Microsoft.SqlServer.Dac.DacServices.<>c__DisplayClass65.<>c__DisplayClass67.<CreateExportOperation>b__63() at Microsoft.Data.Tools.Schema.Sql.Dac.OperationLogger.Capture(Action action) at Microsoft.SqlServer.Dac.DacServices.<>c__DisplayClass65.<CreateExportOperation>b__62(Object operation, CancellationToken token) at Microsoft.SqlServer.Dac.Operation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context) at Microsoft.SqlServer.Dac.OperationExtension.CompositeOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context) at Microsoft.SqlServer.Dac.OperationExtension.Execute(IOperation operation, DacLoggingContext loggingContext, CancellationToken cancellationToken) at Microsoft.SqlServer.Dac.DacServices.ExportBacpac(Func1 streamGetter, String databaseName, DacExportOptions exportOptions, IEnumerable1 tables, CancellationToken cancellationToken) at Microsoft.SqlServer.Dac.DacServices.ExportBacpac(String packageFileName, String databaseName, DacExportOptions options, IEnumerable1 tables, Nullable1 cancellationToken) at Microsoft.SqlServer.Dac.DacServices.ExportBacpac(String packageFileName, String databaseName, DacSchemaModelStorageType modelStorageType, IEnumerable1 tables, Nullable1 cancellationToken) at Microsoft.SqlServer.Management.Dac.DacWizard.ExportDatabase.DoWork() at Microsoft.SqlServer.Management.TaskForms.SimpleWorkItem.Run()

ssreerama commented 6 months ago

Tested with the Spanish language too, And the generated bacpac has no issues and clearly accepting the special characters. Like you suspected, it could be customer's machine's configurations issue or something else, If we can get more info related versions and tools they are using, we can give a try. Thanks

image

llali commented 1 hour ago

I fixed the log to show the failure. I also checked that the origin.xml is created after model.xml so if model.xml fails, there shouldn't be any origin.xml. it is possible that the bacpac file already existed. dacfx support exporting to existing bacpac file. so if it fails it should not delete the bacpac.