Create Data Connection in InfoPath in SharePoint

This InfoPath tutorial explains, how to create a data connection from a SharePoint 2010 list in InfoPath 2010. We need to create data connections to retrieve data from other lists in InfoPath 2010 in SharePoint 2010. We will check below things:

  • Create Data Connections in InfoPath 2010 in SharePoint 2010
  • Create XML data connection in InfoPath in SharePoint 2010
  • Create SQL data connection in InfoPath in SharePoint
  • How to create a udcx file for Main Data Connection in InfoPath

Create Data Connections in InfoPath 2010 in SharePoint 2010

Follow below steps to create a data connection in InfoPath 2010 in SharePoint 2010.

Step-1:
Open InfoPath 2010 (Start -> All Programs -> Microsoft Office -> Microsoft InfoPath Designer 2010), then select Blank Form and Click on Design Form.

Step-2:
From the Ribbon select Data tab and select Data Connections as shown in the figure below:

create data connection in infopath

Step-3:
In the Data Connections wizard click on Add… as shown in the figure below:

create data connection in infopath 2010

Step-4:
In the next step select Create a new connection to Receive data and click on Next as shown in the figure below:

create data connection in infopath 2013

Step-5:
In the next step select SharePoint library or list and click Next as shown in the figure below:

create data connection in infopath sharepoint

Step-6:
In the next step give the SharePoint site details and Click on Next as shown in the fig below:

create data connection in infopath 2010 sharepoint

Step-7:
Then Select the list from which you want to bind the data as shown in the fig below:

create data connection in infopath 2013 sharepoint

Step-8:
In the next step, select the fields which you want to retrieve and sort order and click on Next as shown in the fig below:

how to create data connection in infopath

Step-9:
Then click on Next and do not modify anything for Store a copy of the data in the form template.

Step-10:
Then give a name for the data connection and select the checkbox. Automatically retrieve data when form is opened as shown in the fig below and click on Finish.

how to create data connection in infopath 2013

This creates a data connection in InfoPath 2010 in SharePoint 2010.

Create XML data connection in InfoPath in SharePoint 2010

Create XML data connection in InfoPath in SharePoint 2010

Now, we will discuss how to create a data connection in an XML file in InfoPath 2010 in SharePoint 2010.

Below are the steps on how to create a data connection with XML file in InfoPath:

Suppose we want to retrieve some field data like first name, last name etc. So we first we have to create XML file. Just copy the below code and paste it on a notepad and save it as template.xml.

<?xml version="1.0" encoding="UTF-8"?>
<Batch OnError="Continue">
<Method ID="1" Cmd="New">
<Field Name=’Title’></Field>
<Field Name="FirstName"></Field>
<Field Name="LastName"></Field>
<Field Name="Email"></Field>
<Field Name="Phone"></Field>
</Method>
</Batch>

Now open a blank form library. Open InfoPath designer 2010 Go to Data tab, click on data connection and then click on Add.

Now choose your type of connection to submit data/receive data and click on Next.

Create XML data connection in InfoPath in SharePoint 2010

Now choose XML document from the radio buttons and click on Next.

Create XML data connection in InfoPath sharepoint 2010

Now click on browse and choose your xml file as we created “template.xml”.

Create XML data connection in InfoPath in SharePoint 2010

Now click on next and lastly provide the data connection name as you want. Now your XML data connection is ready to retrieve data inside InfoPath 2010 form.

Create SQL data connection in InfoPath in SharePoint

In this SharePoint 2013 InfoPath tutorial, I am going to explain how to create SQL data connection in InfoPath 2013 and how to get the data from SQL table into your InfoPath form in SharePoint 2013.

Open your InfoPath form and click on the DATA tab from the ribbon. Then click on Data connection and then click on Add. Now from the dialog box check on “Receive Data”. Now from the next dialog box choose “Database”.

Now click on select Database and click on “Connect to New Data source” and open. From the data connection wizard choose “Microsoft SQL Server”, Now it will ask for your SQL server name.

Create SQL data connection in InfoPath in SharePoint

Give the server name->next and choose windows authentication or SQL authentication as per your requirement. In the next dialog box select your database and then choose your desired table and click on next. In the next dialog box, you can change the name or you can keep that name.

In the next dialog box, check on your desired columns and then click on next->next. In this dialog box, you can give the name data connection or you can keep the name provided by the system and uncheck “Automatically retrieve data when the form is opened”.

Create SQL data connection in InfoPath in SharePoint 2013

Finally, click on finish and your data connection is created. This way we can create SQL data connection in InfoPath in SharePoint.

How to create a udcx file for Main Data Connection in InfoPath

Now, we will see how to create udcx file for the main data connection in InfoPath 2013 SharePoint 2013.

To create an UDCX file follow the below steps.

Step-1 Create a data connection library in InfoPath 2010

Open your SharePoint server and click on Add on the list, library and another app. Then click on the Data connection library and provide the name and click on create. Now your data connection library is created and now will go to the next step.

Step-2 Create udcx file in InfoPath

Open your InfoPath form and click on Data->Data connection. From the dialog box click on your data connection name you want to convert and then click on “Convert to connection file”. Now it will ask for the data connection path we created on step-1. Provide the udcx file name as below.

http://site url/dataconnection library name/udcx file name.

Then click on ok as shown in the fig below:

create a udcx file for Main Data Connection in InfoPath

Now go to your site and approve the udcx file uploaded in the data connection library. Now you can work with your udcx file using rules to retrieve data.

Difference between Main and secondary data sources in InfoPath

Let us see what is the difference between the main data source and secondary data sources in InfoPath 2010 in SharePoint 2010.

Every data showed in an InfoPath form, is stored in form’s data source. A data source contains fields and groups. Then suppose you add a control then this control is bound to those fields.

There are 2 types of data sources in InfoPath 2010:

  • Main data source
  • Secondary data sources

A form will have a single main data source by default and may or may not contain one or more secondary data sources.

Main data source in InfoPath 2010

The main data source in InfoPath 2010 contains the data that users add when they fill out a form that is based on the form template, such as the data that they enter into a text box.

It also contains the data from a data connection to a database or Web service, which is used to define the data source of the InfoPath 2010 form template.

When you create a form template, Microsoft Office InfoPath automatically creates the main data source.

Secondary data sources in InfoPath 2010

Secondary data source in InfoPath, are data sources in the form that contain data supplied through other data connections to external data sources.

The data from additional data connections is stored in secondary data sources and then displayed. You can check this article to know how to create a data connection in InfoPath 2010.

Difference between the Main data source and Secondary data sources

  • Secondary data sources are optional in a form template. But all form templates must have the main data source.
  • A form template can have one or more secondary data sources but only a single main data source.
  • Fields and groups in a secondary data source are based on the way that data is stored in the external data source, which is connected to the form by using a data connection. These fields and groups cannot be modified by using InfoPath.
  • Unlike the main data source, secondary data sources are not saved with the form.

Data in secondary data sources are not typically submitted when the user submits a completed form. However, you can configure your form template to submit the data in the secondary data source to a Web service by using rules or to an e-mail recipient by using custom code.

Programmatically access data sources in InfoPath 2010

Main Data Source:
Below is the code to access the main data source using C#.Net code in Infopath 2010:

XPathNavigator mds = MainDataSource.CreateNavigator();

Secondary data source:
Below is the code to access the secondary data source using C#.Net code in InfoPath 2010:

XPathNavigator sds = DataSources[“dataconnectionName”].CreateNavigator();

Example:
XPathNavigator sds = DataSources[“Employees”].CreateNavigator();

Updated:
Here are few very good points I am adding which I got to know from bizsupportonline URL.

The Main InfoPath data source of a form contains the data that you want to permanently store when you save the form in InfoPath 2010 in SharePoint 2010.

You may like following InfoPath tutorials:

Here, we saw how to create a data connection in InfoPath in SharePoint and also we saw below examples:

  • Create Data Connections in InfoPath 2010 in SharePoint 2010
  • Create XML data connection in InfoPath in SharePoint 2010
  • Create SQL data connection in InfoPath in SharePoint
  • How to create a udcx file for Main Data Connection in InfoPath
Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>