Data connections overview
A data connection is a dynamic link that is used to receive or submit data between a Microsoft InfoPath form and data that is saved outside the form, such as a SharePoint server, Web service, or database. For example, in an order form that contains a list of available products, the static list of product names could be saved in the form. However, any time a product is added or removed, the product list in the form must be updated.
To make sure that the form stays up-to-date, save and maintain the product information outside the form. Create a data connection to add this information to the form when users fill out the form. The benefit of using a data connection to retrieve the product information is that this information can be saved in a single place that multiple forms can link to. Also, you are assured that users always have the latest information when completing a form.
In addition to receiving data, data connections can be used to submit data. After a user has filled out a form, they must submit the form. By adding submit data connections to forms, you can specify where the form data is submitted. For example, a form can be submitted as a document to a SharePoint document library or sent in an email message.
In this article
Local versus external data
All InfoPath forms save the data that is entered into them. Controls are used to display the data to users. When a user submits the form, the local data in the form is submitted to one or more external locations.
Data connections can be used when you need to query data from outside the form, or when you want users to submit data to multiple locations. There is no limit to the number of data connections that can be created.
If you create a data connection that queries data, the form queries this data connection by default when the form opens. You can also use this data connection by configuring the form in the following ways:
Add a refresh button that users click to query the external data
Add a rule to query the external data by using this data connection
Add custom code that queries the external data based on some other event
External data connection types
You can create submit data or receive data connections to exchange data with a data source outside of a form.
Submit data connection
When users submit a form that is based on a SharePoint list or a database, the list or database is updated with the changes made by the user when they submit the form. A form can also be configured to allow users to send data to other locations. The following external data locations can be used:
Document library on a SharePoint site
Hosting environment (such as an ASP.NET page or a hosting application)
In most cases, one submit data connection is used when the form is submitted. However, a form can submit data to multiple locations by using rules or custom code. For example, forms can be submitted to a Web service as well as through an email message. Typically, forms are configured to submit all of the data in the form. However, with custom code to submit the form data or configure the form to submit data to a Web service you can choose to submit only a portion of the form data.
Receive data connection
A receive data connection gets data from an external source to populate fields in the form. Controls can then be bound to those fields to display the data from the external source in the form. For example, a receive data connection is commonly used to populate a drop-down list box. The following sources can be used:
SOAP Web service
REST Web service
SharePoint library or list
Database (Microsoft SQL Server only)
Saving data for offline use
Sometimes, a user might want to fill out an InfoPath form when they are not connected to a network, also known as working offline. You can add a data connection that queries data from a data connection and configure the connection to save the results of the query on the user's computer. This ensures that users can fill out the form if their computers are working offline.
If you configure a data connection this way, the query is sent through the data connection while the user is filling out the form and their computer is connected to the network. The results of the query are then saved to the user’s hard disk in the form and they appear when the user fills it out. Data is cached each time the user performs a new query so that the data is kept up-to-date as much as possible.
When you create the data connection, you can choose whether to display a default set of saved data in the form, in case the external data connection is not available. You should consider whether the data from the query is appropriate for all of your users or whether the form should display user-specific data. For example, if the data returned by the query is based on the user's identity or role, using a default set of data that was configured at design time instead of using query results might result in incorrect data for that user.
Base a form on an external source of data
By using the SharePoint list, database, or Web service, you can design a form template based on a receive data connection. Fields and groups are created locally, in the form, that correspond to the fields and groups in the external data repository. In other words, InfoPath 2010 locally mirrors the data structure of the external data so that, when the form loads the external data, there are no data integrity issues.