+ Start a Discussion

Making SQL database connections from APEX code


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?

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.
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.
How to create a webservice API that connects to this database and address the API using callout's in APEX?
any specific samples?

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)