Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

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

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.

  • MS57 Profile Picture
    MS57 5 on at
    RE: Access denied trying to connect to CRM 365 via SDK in Web application

    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

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Access denied trying to connect to CRM 365 via SDK in Web application

    You are welcome! Glad that it resolved your issue.

  • MS57 Profile Picture
    MS57 5 on at
    RE: Access denied trying to connect to CRM 365 via SDK in Web application

    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.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Access denied trying to connect to CRM 365 via SDK in Web application

    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;"

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans