How to Reattach an SQL Data Source to a Word Document
Question details
The user needs to reconnect a Word document to an SQL data source to fix mail merge commands that are failing to run in certain files.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Executing a mail merge where the SQL command or data connection works in one document but disconnects or fails in others.
- Observed behavior
- The connection to the SQL data source drops or the mail merge configuration is lost, preventing the query from running successfully in the affected documents.
Ensure you have the necessary network access and login credentials for the SQL database before attempting to reconnect the data source.
Reconfigure the Mail Merge Main Document
Reset the document type and reattach the SQL data source to restore mail merge functionality.
When a Word document loses its connection to an SQL database, the mail merge configuration must be explicitly reset. By redefining the document type and re-selecting the data source, you force the application to re-establish the connection parameters.
Launch your word processor and open the specific document that is failing to run the SQL command.
Navigate to the 'Mailings' tab on the top ribbon, click 'Start Mail Merge', and select your preferred document type (such as 'Letters' or 'Email Messages').
Click 'Select Recipients' and choose 'Use an Existing List'. Browse to your SQL database connection file (.odc) or enter your server credentials to connect directly to the database.
Once connected, click 'Edit Recipient List' to confirm that your SQL query is successfully pulling the correct data and connection settings are active.
Save the document immediately. This binds the new mail merge configuration and SQL connection settings to the file for future use.

Easily Manage Mail Merge and Data Sources with WPS Office
WPS Office provides a highly intuitive Mail Merge feature that makes it simple to connect external data sources, including databases and spreadsheets, to your documents without complex configuration.
- 1. Access Mail Merge: Open WPS Writer and navigate to the 'References' or 'Mailings' tab on the top ribbon.
- 2. Activate the Tool: Click on 'Mail Merge' to activate the dedicated merge toolbar.
- 3. Connect Data Source: Select 'Open Data Source' to quickly connect your database, query file, or spreadsheet to the current document.
- 4. Insert Fields and Merge: Insert the required merge fields into your document and click 'Merge to New Document' to generate your final files.

Frequently Asked Questions
Why does my Word document lose its SQL data source connection?
Security settings in modern word processors often prompt users to confirm SQL commands upon opening a document to prevent malicious code execution. If this prompt is dismissed, or if macros and data connections are disabled in the Trust Center, the document will drop its link to the data source.
How do I fix the 'SQL command failed' error during a mail merge?
This error typically occurs if the database schema has changed, the server is offline, or permissions are restricted. Verify your SQL connection string, check your database access rights, and reattach the data source fresh using the 'Select Recipients' option.
Can I use an Excel file instead of an SQL database for mail merge?
Yes, Excel spreadsheets are highly compatible with the Mail Merge feature and are often easier to manage than SQL databases for simpler tasks. Choose 'Use an Existing List' in the Mailings tab and select your .xlsx file instead of an SQL connection file.




