This article is part of a series of documents explaining the Data concept in Microsoft Office InfoPath. This particular article is an overview of how Data Connections work in InfoPath. The intended audience is those who are new to InfoPath and those who use InfoPath, but have not built up knowledge in the way Data Connections work. For more exhaustive information regarding specific types of data connection, see the Links section at the end of this article.
Definitions of certain terminology in this paper are as follows:
- InfoPath client – the software program named "Microsoft Office InfoPath"
- Designer – The person who is using the InfoPath client to create/design a form template
- Form template – the XSN file that is created with InfoPath client and used to enter data by the form filler
- Filler – the person who is putting data into the form
- Form – a form that is either filled out or in the process of being filled out by the filler. Also known as the InfoPath XML file.
- Document Object Model (DOM) – XML structures in the form. In InfoPath, there is a Main DOM on which the form is based and Secondary DOMs which hold data received from Receive Data Connections.
The purpose of using an InfoPath form is to collect structured data. This data structure is represented by a schema (XSD) which defines the data fields and the hierarchical structure of the data.
When using InfoPath client, data is accessible through data connections. These data connections are defined in the form template and used at runtime. During design of the form, the form designer will create the data connection. The designer must choose to either create new settings for a data connection or search for existing connections previously defined by an admin on a SharePoint server. In general, the data connection paradigm in InfoPath 2003 and 2007 is such that data connections are grouped into one of two types – submit connection type or receive (query) connection type. Receive connection types have a one-to-one relationship with secondary DOMs.
Submit Data Connections
Consider this scenario. The form filler places data into all of the fields on the form, presses a button labeled “Submit my data” and the data is pushed to some listener where it can be stored or processed.
As simple as this scenario is, it must be configured by the form designer through the Submit type of data connection. After creating a submit data connection, the designer can apply the data connection to a user action – in this case, the button labeled “Submit my data”. When the filler executes that action, data in the main DOM of the form is transmitted to the target of the data connection as a submission.
Submit data connections can currently bind to the following destinations:
- Web Service – Using a data connection bound to the Web Services adapter, data is submitted according to the specifications of the web service.For web services that expose the type System.Dataset, InfoPath will track changes as the user edits the data. When the data is submitted to the web service, the changes are sent using ADO.NET Diffgrams.
- SharePoint document library – Data is submitted to a SharePoint document library by using a data connection bound to the SharePoint Document Library adapter.
- E-mail – Using a data connection bound to the SMTP E-Mail adapter, this enables the submission to an e-mail address. The settings of the data connection can specify whether to submit the entire contents of the form as an attachment or just the current view as the body of the e-mail message.
- The form hosting environment, such as an ASP.NET page or a hosting application (2007 ONLY) – Using a data connection bound to the “Submit to host” adapter, this raises a submit event to the host. The host is then responsible for handling that event and retrieving the data from the form. See http://msdn2.microsoft.com/en-us/library/ms778201.aspx for more info.
- Web Server (HTTP) – This is one exception where the submission is not bound to an adapter as a data connection, rather, the settings of the submit options on a control specify an HTTP URL. HTTP Post is used to submit the data in the form to that URL.
- Database – Lastly, if the form is initially designed from a SQL Server or Access database, a submit action can be created to push the data back into that database. Note: the database option has some caveats in that large binary types cannot be submitted from InfoPath directly; these require a web service in front of the database.
Receive Data Connections
One of the major problems in filling out forms is accuracy of data. For instance, if someone was replying to a survey regarding what their favorite programming language is, they could have a text box to type it in. Now imagine that there are 50 respondents to the survey, each trying to explain in a text string what their favorite language is. Consider for a moment that it is C#. They could respond with any of the following and be just a correct or valid: C#, C-Sharp, Csharp, C, C# .NET. Obviously, allowing this type of data entry will create problems when the survey is interpreted.
This type of scenario is a good reason to use a Receive data connection. What if the form designer was to pre-populate a drop-down control with specific choices which the filler could choose as their favorite programming language? The designer could create a list such as: VB, C++, VB.NET, C# and would thus ensure that the filler would be able to be successful in filling out the form with valid data that is consistent across all of those who respond. The person who aggregates the responses from the form will also be able to ensure that they have interpreted the data correctly and completely.
To configure this scenario, the form designer now needs to create a Receive connection type. A receive data connection allows a query to be made to get data from an external source and return it to the form. External data is placed into the form as a secondary data source (represented as another DOM). Controls can then be configured to use these fields. Also, the designer can view the additional data sources by viewing the Data Source task pane and using the drop down to switch between data sources. If the dropdown is grey, then there is only one data source in the form.
Receive data connections can currently connect to the following sources - all of these are supported in InfoPath 2003 and 2007:
- XML Document – This includes any URL that would return an XML document (For instance, an RSS feed)
- Database (Microsoft SQL Server or Microsoft Access only)
- Web Service
- SharePoint document library or list
For further and comprehensive information regarding data connections in InfoPath, see http://office.microsoft.com/en-us/infopath/HP012304861033.aspx?pid=CH100598301033
For more information specific to data connections to Web Services, see http://office.microsoft.com/en-us/infopath/HP100913971033.aspx?pid=CH100598301033
For more information on using InfoPath with Access, see http://office.microsoft.com/en-us/infopath/HP100950831033.aspx?pid=CH100598301033
For more information on using InfoPath to connect to SharePoint data sources, see http://office.microsoft.com/en-us/infopath/HP100931601033.aspx?pid=CH100598301033
For general topics of interest and further How To information on InfoPath data connection, see http://office.microsoft.com/en-us/infopath/CH100598301033.aspx