function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kmchalekmchale 

Making SQL database connections from APEX code

Hi,

I'm just wondering does anyone know if it's possible to make connections to external database servers such as MS SQL Server or MySQL from Apex code. If so, how would one go about this?

Thanks
HarmpieHarmpie
I don't think a direct connection to an external database is possible. What you could do is create a webservice API that connects to this database and address the API using callout's in APEX.
kmchalekmchale
Hi Harmpie,

Thanks for the reply. I wasn't sure that it was possible myself. I think setting up an API is the approach I'll have to take.

Thanks for your help.
Steven2005ASteven2005A
How to create a webservice API that connects to this database and address the API using callout's in APEX?
 
any specific samples?
CloudIntegratorCloudIntegrator

I think the answer goes back to "Why" you want to connect back to your MySQL or SQL Server.  

 

If you are looking to do Events or single transactions,  the web service approach is a good one.   Here you can push a button on your SFDC page to call out to your custom web service to get or put data into your back-end system.   You can also setup outbound messages in SFDC workflow to postback to your webservice (schema defined by SFDC though) based on events.  Creating a webservice in your enterprise is pretty easy.    Most languages, you just specify the method as a webservice. (.NET shown)

 

[WebMethod] public Customer[] GetCustomersByName(string Name)

{}

 

Don't forget that once you make a web service, you also need to expose it in your DMZ and give it a name so that SFDC can access it.   

 

 

If you are interested in synchronizing data between SFDC and your backend database, you should probably look at some of the free Data Loader tools out on App Exchange.   

 

SFDC Data Loader with Databases

 

HowTo Free IOD DLS and SFDC DL

 

Best Apps of 2008 (find Integration)

 

Regards,

 

CloudIntegrator

www.InformaticaOnDemand.com