I'm definitive new on Dynamic CRM 2011, so maybe this question is really easy.
I'm connecting throw a WCF Service to instances of CRM whit this part of code: 实例,这部分代码:
var settings = new ConnectionStringSettings("Xrm", connectionString);
var connection = new CrmConnection(settings);
using (var xrm = new XrmServiceContext(connection))
{
//do the magic here
}
The "connectionString" parameter, is a string containing the connection string of the CRM.
So, the problem is that the first time it's connects fine to the server that I write in the connectionString, but then, It always connect to the same server, I mean, even if I change the server address, always tries to connect to the first one.
Debugging, I look in the
var connection = new CrmConnection(settings);
And is always the same connection to the first server....
So, I need a way to dispose that connection, or force the constructor to always create a new instance... or something like that... But I can't find the method, or operation that do that...
Thanks in advance!
Ok, I found a solution, I don't know if is the best solution, but it works...
Instead of using this
var settings = new ConnectionStringSettings("Xrm", connectionString);
var connection = new CrmConnection(settings);
I use
var connection = CrmConnection.Parse(connectionString);
That's giving me the same result, and always with the right connection string
The underlying issue here is that some properties are cached for each ConnectionStringSettings
. You can avoid this by giving using a unique name for each instance (eg: Xrm1, Xrm2 etc). I'm not sure thus behaviour is explicitly documented in the SDK but I've certainly encountered it and fixed it as I indicated.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.