Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamics CRM SDK in C# connect with Invalid Password

I am developing one C# application which is used to retrieve data from Dynamics CRM Online. To validate the User Name and Password of Dynamics CRM I am using the WhoAmIRequest. It works fine until the below scenario occures.

1)Connect the Dynamics CRM with Valid URL, User Name and Password.

2) Dispose the Organization Service Object.

3) Reconnect the Dynamics CRM with Valid URL, User Name and Invalid Password.

In this scenario also the WhoAmIRequest got executed Successfully. But it should fail.

Below is the code i am using:

private void button6_Click(object sender, EventArgs e)
    {
        CrmConnection connection;
        string url = "Url=https://mytest.crm.dynamics.com ;[email protected]; Password=goodpassword;";
        connection = CrmConnection.Parse(url);
        OrganizationService orgService = new OrganizationService(connection);
        Guid userid = ((WhoAmIResponse)orgService.Execute(new WhoAmIRequest())).UserId;
        if (userid == null)
            MessageBox.Show("Login Failed");
        else
            MessageBox.Show("Login Success");
        orgService.Dispose();

        url = "Url=https://mytest.crm.dynamics.com ;[email protected]; Password=badpassword;";
        connection = CrmConnection.Parse(url);
        orgService = new OrganizationService(connection);
        userid = ((WhoAmIResponse)orgService.Execute(new WhoAmIRequest())).UserId;
        if (userid == null)
            MessageBox.Show("Login Failed");
        else
            MessageBox.Show("Login Success");
        orgService.Dispose();

        url = "Url=https://mytest.crm.dynamics.com ;[email protected]; Password=goodpassowrd;";
        connection = CrmConnection.Parse(url);
        orgService = new OrganizationService(connection);
        userid = ((WhoAmIResponse)orgService.Execute(new WhoAmIRequest())).UserId;
        if (userid == null)
            MessageBox.Show("Login Failed");
        else
            MessageBox.Show("Login Success");
        orgService.Dispose();
    }

The output of above code shows 3 message box as

Login Success

Login Success

Login Success

But it should show as

Login Success

Login Failed

Login Success

I have also tried the answer suggest by Nicknow in the the Need to validate CRM credentials Question but nothing helps

Any help will be highly appreciated.

Thanks and Regards Venkatesan

like image 942
user3270512 Avatar asked Jun 24 '15 06:06

user3270512


People also ask

What is Dynamics CRM SDK?

The CRM SDK is the main tool for a CRM developer, the better a CRM developer knows its capabilities, limitations and documentation the more efficiently they can do their job.

Is there coding in Microsoft Dynamics?

You can learn Dynamics 365 without having any coding knowledge and work as Functional Consultants or end-users. However, if you want to be a Technical Consultant, you must understand the fundamentals of C# . NET, HTML, and JavaScript.

Is Dynamics built on SQL?

Dynamics 365 Server requires an instance of SQL Server Reporting Services be installed, running, and available. All installations of the supported SQL Server editions can be used as the reporting server. However, the Reporting Services edition must match the SQL Server edition.

Does dynamics have an API?

The Customer Engagement Web API provides a development experience that can be used across a wide variety of programming languages, platforms, and devices. The Web API implements the OData (Open Data Protocol), version 4.0, an OASIS standard for building and consuming RESTful APIs over rich data sources.


1 Answers

The problem is in your check here:

if (userid == null)

UserId is a Guid, Guid is a struct, a struct is a value type, and a value type will never be null, so that check always returns false.

See here for more information Guid == null should not be allowed by the compiler

I would suggest using the following check instead:

if (userid == Guid.Empty)

like image 116
James Wood Avatar answered Sep 22 '22 08:09

James Wood