Visual Studio 2010
Project menu--Add reference..
Add a reference to Microsoft.BusinessData.dll (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\)
Add a reference to Microsoft.Office.SecureStoreService.dll (C:\Windows\assembly\GAC_MSIL\Microsoft.Office.SecureStoreService\14.0.0.0__71e9bce111e9429c\)
Retrieve Username and password in Secure Store Service
SharePoint 2010 Central Administration--Application Management--Service Applications--Manage service applications
![]()


The Field Type is important. The Field Name is not important. When I change "Windows User Name" field name to AAA and "Windows Password" to BBB, I still can restrieve the stored username and password.


Visual Studio 2010 Professional
Create a new project


Type in code as shown below:
(0):
<Method Name="GetEntity">
<FilterDescriptors>
<FilterDescriptor Type="Username" Name="UsernameFilter" />
<FilterDescriptor Type="Password" Name="PasswordFilter" />
</FilterDescriptors>
<Parameters>
<Parameter Name="username" Direction="In">
<TypeDescriptor TypeName="System.String" Name="username" AssociatedFilter="UsernameFilter" />
</Parameter>
<Parameter Name="password" Direction="In">
<TypeDescriptor TypeName="System.String" Name="password" AssociatedFilter="PasswordFilter" />
</Parameter>
</Parameters>
</Method>

(1):

<Properties>
<Property Name="SecondarySsoApplicationId" Type="System.String">QueenID</Property>
<Property Name="SsoProviderImplementation" Type="System.String">Microsoft.Office.SecureStoreService.Server.SecureStoreProvider, Microsoft.Office.SecureStoreService,Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Property>
</Properties>
(2):

<FilterDescriptors>
<FilterDescriptor Name="UserNameFilter" Type="Username" />
<FilterDescriptor Name="PasswordFilter" Type="Password" />
</FilterDescriptors>
<Parameter Name="username" Direction="In">
<TypeDescriptor TypeName="System.String" Name="username" AssociatedFilter="UserNameFilter" />
</Parameter>
<Parameter Name="password" Direction="In">
<TypeDescriptor TypeName="System.String" Name="password" AssociatedFilter="PasswordFilter" />
</Parameter>
(3):

<FilterDescriptors>
<FilterDescriptor Name="UserNameFilter" Type="Username" />
<FilterDescriptor Name="PasswordFilter" Type="Password" />
</FilterDescriptors>
<Parameter Name="username" Direction="In">
<TypeDescriptor TypeName="System.String" Name="username" AssociatedFilter="UserNameFilter" />
</Parameter>
<Parameter Name="password" Direction="In">
<TypeDescriptor TypeName="System.String" Name="password" AssociatedFilter="PasswordFilter" />
</Parameter>
Public Class Entity1Service
Public Shared Function ReadItem(ByVal id As String, ByVal username As String, ByVal password As String) As Entity1
Dim entity1 As New Entity1()
entity1.Identifier1 = username
entity1.Message = password
Return entity1
End Function
Public Shared Function ReadList(ByVal username As String, ByVal password As String) As IEnumerable(Of Entity1)
Dim entity1 As New Entity1()
entity1.Identifier1 = username
entity1.Message = password
Dim myEntityList As Entity1() = {entity1}
Return myEntityList
End Function
End Class
Build and deploy the application

Create an External List based on BDCQueen.Entity1 external content type.

Another example with C#
Important:
The No Code Approach can only work on a Application Target ID with individual type.
If the Application Target ID is GROUP type, the above code does not work. When you open the External List, the error message is:
Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Microsoft SharePoint Foundation-compatible HTML editor such as Microsoft SharePoint Designer. If the problem persists, contact your Web server administrator.

Project Name:BdcSharp
SQL Server connection string
Initial Catalog=ShareDB;Data Source=Queen;User ID=sa;Password=mypassword
Queen SQL Server security: SQL Server and Windows Authentication mode
Project with c#
Project Name:BdcSharp
SQL Server Security: Windows Authentication mode
SQL server connection string
Initial Catalog=ShareDB;Data Source=Queen;Integrated Security=SSPI
Impersonate user