Database Field Not Updating

Hello

Am using a DATABASE FIELD in Word.

Am calling:
doc.UpdateFields()
However the DATABASE field is not updating.

DATABASE FIELD connection string is:
Driver={ODBC Driver 17 for SQL Server};Server=SERVERNAME;Database=DBNAME;Trusted_Connection=yes;

Hi

I also run this example code and the Database Field does not update.

When I open word and
Ctrl-A → Right Click → Update Field
The DATABASE field is updated.

@tcullen Could you please attach your document here for testing? We will check the issue and provide you more information.
Also, please make sure you can connect to the database with the specified connection string in the same environment you perform processing the document using Aspose.Words.

Field.DATABASE.docx (17.7 KB)

Here is the C# code to generate database field. It successfully updates if run manually in word.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose.Words;
using Aspose.Words.Fields;


namespace AsposeDocxtoPdf
{

    class Program
    {
        

        static void Main(string[] args)
        {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // This DATABASE field will run a query on a database, and display the result in a table.
            FieldDatabase field = (FieldDatabase)builder.InsertField(FieldType.FieldDatabase, true);
            field.FileName = "C:\\temp\\debtrakccc.odc";
            field.Connection = field.Connection = "Driver={ODBC Driver 17 for SQL Server};Server=SERVERNAME;Database=DBNAME;Trusted_Connection=yes;";
            field.Query = "SELECT GETDATE(),'This timestampe is not being updated'";
            field.FirstRecord = "1";
            field.LastRecord = "10";

            // This property is the index of the format we want to use for our table. The list of table formats is in the "Table AutoFormat..." menu
            // that shows up when we create a DATABASE field in Microsoft Word. Index #10 corresponds to the "Colorful 3" format.
            field.TableFormat = "10";

            // The FormatAttribute property is a string representation of an integer which stores multiple flags.
            // We can patrially apply the format which the TableFormat property points to by setting different flags in this property.
            // The number we use is the sum of a combination of values corresponding to different aspects of the table style.
            // 63 represents 1 (borders) + 2 (shading) + 4 (font) + 8 (color) + 16 (autofit) + 32 (heading rows).
            field.FormatAttributes = "63";
            field.InsertHeadings = true;
            field.InsertOnceOnMailMerge = true;
            field.Update();		// Try and update field
            doc.UpdateFields();
            doc.Save("C:\\Temp\\Field.DATABASE.docx");

        }
    }
}

@tcullen Could you please also attach your sample database, you use for testing?

field.FileName = "C:\\temp\\debtrakccc.odc";

Hi
Am unable to provide the database as is a large SQL Server 2019 database.
I do not believe it is a database connection string issue.

Hi
I have successfully reproduced the issue of the database field not updating with an Excel Data Source which you can test.
Save files in C:\Temp
DBTest.zip (22.8 KB)
C# Code to create the DATABASE Field.
You can successfully manually update the field. Open Word Document->Ctrl-A->Right Click Update Field

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// This DATABASE field will run a query on a database, and display the result in a table.
FieldDatabase field = (FieldDatabase)builder.InsertField(FieldType.FieldDatabase, true);
field.FileName = "C:\\Temp\\DBTest.xlsx";
field.Connection = field.Connection = "Driver={Microsoft Excel Driver(*.xls)};Dbq=C:\\Temp\\DBTest.xls;Readonly;";
field.Query = "SELECT * FROM [Table1$]";
field.FirstRecord = "1";
field.LastRecord = "10";
// This property is the index of the format we want to use for our table. The list of table formats is in the "Table AutoFormat..." menu
// that shows up when we create a DATABASE field in Microsoft Word. Index #10 corresponds to the "Colorful 3" format.
field.TableFormat = "10";

// The FormatAttribute property is a string representation of an integer which stores multiple flags.
// We can patrially apply the format which the TableFormat property points to by setting different flags in this property.
// The number we use is the sum of a combination of values corresponding to different aspects of the table style.
// 63 represents 1 (borders) + 2 (shading) + 4 (font) + 8 (color) + 16 (autofit) + 32 (heading rows).
field.FormatAttributes = "63";
field.InsertHeadings = true;
field.InsertOnceOnMailMerge = true;
field.Update();		// Try and update field
doc.UpdateFields();
doc.Save("C:\\Temp\\Field.DATABASE.docx");

@tcullen Thank you for additional information. Aspose.Words does not support updating DATABASE fields. This feature has been logged as WORDSNET-15752. We will let you know once it is implemented.

Hello is there an update on this issue.
Aspose Words offers extremely limited ability to add tables to Mail Merge documents without significant programming per table.
Supporting updating a DATABASE field would be a significant improvement / enhancement.
Additionaly Aspose Words supports the Creation of a DATABASE field but does not update it when rendering a document so clearly a bug / issue.

@tcullen Unfortunately, the issue is still not resolved. This feature is scheduled to be implemented in 22.8 (August 2022) version of Aspose.Words. But, please, note, this is a rough estimate and can be shifted, so you cannot 100% rely on it.

The issues you have found earlier (filed as WORDSNET-15752) have been fixed in this Aspose.Words for .NET 22.7 update also available on NuGet.

@tcullen Please see Aspose.Words 22.7 release notes to learn more about updating DATABASE fields.