Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Updating external SQLserver from inside a Plugin

Posted on by 255

Hi

I'm extracting data from multiple CRM entities when the modified date changes using Fetch XML.
This seems OK and I've populated my vars ready to process the data.

Next step is to export that data to an external SQLserver instance.

Can I use a simple SqlConnection and SqlCommand inside the Plugin to do this?
Please say yes :)

*This post is locked for comments

  • Stuie Profile Picture
    Stuie 255 on at
    RE: Updating external SQLserver from inside a Plugin

    OK so if i use the following to connect o the webservice from the plugin.
    What is the syntax for passing multiple parameters to the service? (data for the sql insert)

    method name is UpdateApplication

      tracingService.Trace("Start DB insert.");
                    BasicHttpBinding myBinding = new BasicHttpBinding();
                    myBinding.Name = "BasicHttpBinding_ICrmDataInsert";
                    myBinding.Security.Mode = BasicHttpSecurityMode.None;
                    myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                    myBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
                    myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
                    EndpointAddress endPointAddress = new EndpointAddress("http://xxxxxx.com/Service.asmx");
                    CrmDataInsertClient client = new CrmDataInsertClient(myBinding, endPointAddress);


    ..... etc

    Many thanks

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Updating external SQLserver from inside a Plugin

    That cannot be done, but you should be able to use access the web services/api of the SQL Server in order to access data.

    This way you should still be able to use this functionality, but just not ADO/OLEDB.

    Hope this helps.

  • Dynamics_Alok Profile Picture
    Dynamics_Alok 1,746 on at
    RE: Updating external SQLserver from inside a Plugin

    Yes ..If you are using On Premise ,Database call is just a .NET code for you :-) but for on-line either you should go with WebService Option or using some data integration tools like Scribe Insight ,Kingsway ,MuleSoft ,LogicApps etc.For Online deployment of Dynamics CRM ,plugins must be registered in Sandbox mode and it will not allow you to communicate with Database directly.

    IP and address make difference in case of Sandbox Plugins .

  • Stuie Profile Picture
    Stuie 255 on at
    RE: Updating external SQLserver from inside a Plugin

    Hi

    Thank you both for the comments.

    My db is on AWS so I have a string rather than an IP address.

    Does this make any difference here?  

    using (SqlConnection myConnection = new SqlConnection("Data Source=xxxxx.eu-west-1.rds.amazonaws.com;Initial Catalog=APPLICATIONS;User ID=xxxxx;Password=xxxxxxx;Integrated Security=false"))
    
  • Suggested answer
    Radu Chiribelea Profile Picture
    Radu Chiribelea 6,667 on at
    RE: Updating external SQLserver from inside a Plugin

    Hi Stuie,

    Are you using CRM Online or CRM OnPremise? If you are using CRM Online, then you can only use Sandboxed Plug-ins. With those there are some limitations. See msdn.microsoft.com/.../gg334752.aspx :

    "Sandboxed plug-ins and custom workflow activities can access the network through the HTTP and HTTPS protocols. This capability provides support for accessing popular web resources like social sites, news feeds, web services, and more. The following web access restrictions apply to this sandbox capability."

    So i don't think this is possible.

    If the Plug-in doesn't run in Sandboxed mode (onpremise only) - i don't know if this will work or not.

    Maybe it would be worth considering that you have an webservice interface between CRM and your SQL DB. Then CRM can send data to that webservice and the webservice, do the SQL Operations.

    Hope this helps

    Regards,

    Radu

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Updating external SQLserver from inside a Plugin

    as far as I know, the reply is no :)

    due to the limits of the partial trust of the assembly you will not be able to connect directly to an internet exposed sql server.

    However as always you can create and call a webservice and the webservice will take care of doing the updates of your sql server.

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

Featured topics

Product updates

Dynamics 365 release plans