cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MohanKann21
Frequent Visitor

CRUD Operations using custom data provider with Virtual Table

Hi All,

 I created C# Plugins for CRUD operations by referring to this article:

 

"Custom virtual table provider with CRUD operations"

https://docs.microsoft.com/en-us/powerapps/developer/data-platform/virtual-entities/sample-ve-provid....

 

External Database used: Azure SQL dB.

App: Model Driven App in Maker Portal (https://make.powerapps.com)

Registered the Assembly using "PluginRegistration.exe"

Created Data Provider, Data Source

Created Virtual Table, Views, Forms in Model Driven App

Created Sub Area (Form) in Model Driven App and used Virtual Table as Datasource

 

All the records are displayed on Virtual Table's View (Default All View) and Data Tab.

 

I am encountering two issues

1. While running the App, only one record (last record) is displayed on the page, but record count showing correctly.

 

2. Also while performing Add/Edit the following error occurs:

"The specified domain does not exist or cannot be contacted
An unexpected error occurred from ISV code. Error code: 0x80040224"

 

Also attached screen captures. Request your suggestions/help to resolve the issues

 

Regards

 

Mohan

 

 

4 REPLIES 4
MayankP
Resolver II
Resolver II

Hi @MohanKann21 

can you share your retrieve multiple plug in code here ? so we can check and rule out there is no issue at this end..

Hi MayankP,

 

Thanks for your reply.

 

Here is the Retrieve Multiple Plugin Code:

 

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Extensions;
using System;
using System.Data;
using System.Data.SqlClient;

namespace Test.Dataverse.VirtualTable.Plugins
{
public class RetrieveMultiple : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));

EntityCollection collection = new EntityCollection();

string cmdString = "SELECT [Id],[NameType], [Name],[FullName],[Pattern]," +
"[IsError],[IsMovedOut], FROM [dbo].[Person]";
SqlConnection connection = Connection.GetConnection();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = cmdString;
connection.Open();
try
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Entity e = new Entity("new_person");

e.Attributes.Add("new_id", reader.GetInt32(0));

e.Attributes.Add("new_nametype", reader.IsDBNull(1) ? "" : reader.GetString(1));
e.Attributes.Add("new_name", reader.IsDBNull(2) ? "" : reader.GetString(2));
e.Attributes.Add("new_fullname", reader.IsDBNull(3) ? "" : reader.GetString(3));
e.Attributes.Add("new_pattern", reader.IsDBNull(4) ? "" : reader.GetString(4));
e.Attributes.Add("new_isrror", reader.IsDBNull(5) ? 0 : reader.GetInt32(5));
e.Attributes.Add("new_ismovedout", reader.IsDBNull(6) ? false : reader.GetBoolean(6));

collection.Entities.Add(e);
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException("Service Error", ex);
}
finally
{
connection.Close();
}
context.OutputParameters["BusinessEntityCollection"] = collection;
}
}
}
}

 

Thanks,

 

Mohan

MayankP
Resolver II
Resolver II

Hi @MohanKann21 

 

may be this might not be issue but in following line there is extra comma ....

 

string cmdString = "SELECT [Id],[NameType], [Name],[FullName],[Pattern]," +
"[IsError],[IsMovedOut], FROM [dbo].[Person]";

 

I suggest change this to be like this and see if this resolves the issue....

 

string cmdString = "SELECT [Id],[NameType], [Name],[FullName],[Pattern]," +
"[IsError],[IsMovedOut] FROM [dbo].[Person]";

 

Hi MayankP,

 

Thanks for your help.

 

Yes It is typos while sharing the code here and it is corrected... 

 

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Extensions;
using System;
using System.Data;
using System.Data.SqlClient;

namespace Test.Dataverse.VirtualTable.Plugins
{
public class RetrieveMultiple : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));

EntityCollection collection = new EntityCollection();

string cmdString = "SELECT [Id],[NameType], [Name],[FullName],[Pattern]," +
"[IsError],[IsMovedOut] FROM [dbo].[Person]";
SqlConnection connection = Connection.GetConnection();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = cmdString;
connection.Open();
try
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Entity e = new Entity("new_person");

e.Attributes.Add("new_id", reader.GetInt32(0));

e.Attributes.Add("new_nametype", reader.IsDBNull(1) ? "" : reader.GetString(1));
e.Attributes.Add("new_name", reader.IsDBNull(2) ? "" : reader.GetString(2));
e.Attributes.Add("new_fullname", reader.IsDBNull(3) ? "" : reader.GetString(3));
e.Attributes.Add("new_pattern", reader.IsDBNull(4) ? "" : reader.GetString(4));
e.Attributes.Add("new_iserror", reader.IsDBNull(5) ? 0 : reader.GetInt32(5));
e.Attributes.Add("new_ismovedout", reader.IsDBNull(6) ? false : reader.GetBoolean(6));

collection.Entities.Add(e);
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException("Service Error", ex);
}
finally
{
connection.Close();
}
context.OutputParameters["BusinessEntityCollection"] = collection;
}
}
}
}

 

But the issue persists. 

 

Regards,

 

Mohan

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Microsoft Ignite 768x460.png

Find your focus

Explore the latest tools,training sessions,technical expertise, networking and more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,550)