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 365 | Integration, Dataverse...
Answered

Access denied trying to connect to CRM 365 via SDK in Web application

(0) ShareShare
ReportReport
Posted on by 5

I am creating a web application (asp.net) in Visual Studio 2017 that will retrieve data from Microsoft Dynamics 365 (CRM).  This is version 9, ON-PREMISE.

I am developing the app on my workstation.  When I run it in debug mode, it runs on the localhost and the connection to CRM via the SDK works fine as I get the data from CRM as expected.  To further test the application I deployed it to a web server on our network (the same server CRM is running on).  This server is a Windows 2016 Standard box.  The website runs but it can't connect to CRM.  The "LastCRMError" is "Unable to log into CRM.  Access Denied."  Remember, it logs in fine from my workstation.

We are using ADFS for authentication, which is also on-premise.

I've spent two entire days searching for an answer, and trying everything that I have found, all to no avail.  So now I am posting here in hopes that someone out there will have an answer.

Here are the relevant pieces of code:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
CrmServiceClient client = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRMConnectionURL"].ConnectionString);

if (client.IsReady)  <-- This always comes back as false
{

Connection string in web.config: 

connectionString="Url=https://<server>.<domain>.com/CRM; Username=domain\username; Password=password;"  <-- I've tried this with and without the "AuthType" tag.  When using it I've tried "AD", "IFD", and "oAuth."  No difference.

In my VS project, I installed the SDK via NuGet, which is the only way you can get the latest version now.

Apologies if this is the wrong forum and if so, it would be great to be recommended to the correct forum.

Thanks in advance.

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Try to add Domain to connection string with any value like:

    connectionString="Url=https://<server>.<domain>.com/CRM; Username=domain\username; Password=password;Domain=domain;"

  • MS57 Profile Picture
    5 on at

    Andrew,

    You are my hero!  I added the Domain parameter and it worked.  Unbelievable...I spent two days trying to figure this out.  Thanks very much for your help.  I can finally move on with this project.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    You are welcome! Glad that it resolved your issue.

  • MS57 Profile Picture
    5 on at

    Follow up question.  Do you need to close or dispose of the open connection?  The reason I am asking is that when I am running my web app in debug mode on my PC and then make a change in CRM it shuts down my app.  I'm not sure why it does that or if it will happen once I deploy it.

    Thanks again.

    Mike

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 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans