My goal is simple. Using the Dynamics CRM 2013 API and the given URL, username, password, and domain, how can I verify that the values โโare valid?
I have my own application that will use the API. I have a settings screen where the user enters the URL, username, password and domain. I also have a โTest Connectionโ button that will verify that it can connect using this information.
Here is the logic I use to create the connection:
string connectionString; if (_crmDomain != "") connectionString = string.Format(@"Url={0}; Username={1}\{2}; Password={3}", url, domain, userName, password); else connectionString = string.Format(@"Url={0}; Username={1}; Password={2}", url, userName, password); var css = new ConnectionStringSettings("CRMConnectionString", connectionString); var cn = new CrmConnection(css); var service = new OrganizationService(cn);
The problem is that even if the credentials are invalid (possibly the wrong password), the line that creates the new organization works fine. Is there any way to verify that it will work when the final call is completed?
Now I will manage to make a fictitious call. This forces it to create a connection. That's what I'm doing:
var request = new RetrieveAllEntitiesRequest(); request.EntityFilters = EntityFilters.Entity; service.Execute(request);
If the credentials are invalid, the line service.Execute throws an exception. This works fine with one problem. Assume that the user has entered valid credentials and successfully clicked Test Connection. Now let's say that they change the password to be wrong, and click "Test Connection." In this case, he is still doing well. It looks like a pre-existing connection is being used. Is there a way to destroy or clear the previous connection so that when trying with invalid values โโit throws an exception?
Again, my common goal is to check the input values. No matter what provides the best way to achieve this, I will follow them. Thanks!