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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans