web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: Opening and closing connection to CRM from web application

    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.

  • Genato Profile Picture
    56 on at
    RE: Opening and closing connection to CRM from web application

    Do i need to use CrmServiceClient in using statement?

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: Opening and closing connection to CRM from web application

    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.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans