web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to call stored procedure from CRM?

(0) ShareShare
ReportReport
Posted on by 90

Guys,

I want to call a stored procedure from CRM plugin.

Please let me know whether it is possible or not ..

Or do I need to find another approach to fetch data?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    You should create web service.Within that web service you can execute stored procedure.

    You can refer below links to get an idea.

    community.dynamics.com/.../159599

    stackoverflow.com/.../best-approach-to-execute-stored-procedures-from-within-crm-using-a-custom-button

    Mansoor

  • Verified answer
    JayeshAC Profile Picture
    1,157 on at

    Hi Vinit,

    Using Stored procedure is not a recommended way in CRM.

    If your requirement is just to fetch simple data then you can use any of the following method.

    1. using javascript with SOAP/REST call.

    2. using Linq/FetchXML/QueryExpression in plugin/custom workflow.

    If above methods are not working in your case and you have no other option rather than using SP then you can follow the below steps.

    1. Create a SP in SQL

    2. Create a function in plugin/CustomWorkflow to call this SP.

    ---Code to call SP----

    var sProc = "StoredProcedureName";

               using (var connection = new SqlConnection(SqlDatabase.GetCustomConnectionString(OrganizationName)))

               using (var command = new SqlCommand(sProc, connection))

               {

                   command.Parameters.Add("@InputparameterInSP", SqlDbType.UniqueIdentifier).Value = SendValueTOInputParameter;

                   command.CommandType = CommandType.StoredProcedure;

                   command.CommandTimeout = SqlCmdTimeOut;

                   SqlDataAdapter adapter = new SqlDataAdapter(command);

                   DataTable results = new DataTable();

                   adapter.Fill(results);

                   if (results.Rows.Count > 0)

                       return results;

               }

               return null;

           }

    Hope this resolve your requirement...

    Regards,

    Jayesh

  • Vinit Profile Picture
    90 on at

    Thanks for reply Jayesh,

    It's not possible to use JavaScript or linq in this issue because these methods are not able to fetch more than 5000 records.

    That's why someone recommend me to use stored procedure.

    Anyways... Your answer worked out for me..

    Thanks a lot...

  • Suggested answer
    JayeshAC Profile Picture
    1,157 on at

    Fetching 5000 is your problem then you can achieve it through retrievemultiple() method also in QueryExpression.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans