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)

Opening and closing connection to CRM from web application

(0) ShareShare
ReportReport
Posted on by 56

Ok as i mention am working on ASP.NET MVC5 application and am having hard time finding what is the best practice to create, keep open and to close connection to Dynamics CRM 365?

I found some many posts and blogs but everyone pulling on his side of the road.

Some say it's better for every request to open new connection in using statement so it could be closed right away (that's sounds good but it's a possible that requests will be slow because on every request it needs to open new connection to CRM). 
Some say it' better to make singleton object on application scope, keep it open during application lifetime and reuse it on every request.

Normally i would use OrganizationServiceProxy in some simple console app but in this case am not sure should i use OrganizationServiceProxy or CrmServiceClient or something else?

If anyone have or had some similar problem, any hint would be great.

Thank you :)

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    If you use the Crm Service Client, you can set it to use the IDisposable Interface:

    using (CrmServiceClient conn = new CrmServiceClient(creds, authType, internalUrl, "443", orgName, true, true, null))

    {

    }

    The IOrganizationService does not implement the IDisposable Interface.

    Hope this helps.

  • Genato Profile Picture
    56 on at

    Do i need to use CrmServiceClient in using statement?

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    No,

    You can use conn.Dispose() when you are done with the connection.

    This is basically the same for every class that implements the IDisposable Interface.

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