How do I access a database directly from Flex?

This question came from a reader with no name.


I want to use the remote connection in adobe air (Action Script) to connect the database ( oracle, SQL Server etc...)

My short is answer is that you can't do this.

For a longer answer, Most people use some form of middleware; such as ColdFusion, Java, PHP, Ruby, etc... .

So, build a service in your language of choice to access the database; then use RemoteObject from your AIR app to access those services. I'm not sure if AIR will have crossdomain.xml issues or not.

There was an open source project around at one point which used sockets in the Flash player to run SQL directly against a database. I never got the impression it was production ready, though. And I can't find it in Google right now.

I love the questions that are easy to answer. Do you have one to ask me?

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Joe Rinehart's Gravatar Just set up a simple CFC, access="remote" that executes any SQL sent from the client.

(kidding)
# Posted By Joe Rinehart | 1/20/09 9:44 AM
David's Gravatar Joe - I think you'll find that you can tighten you your code if you leave out those pesky CFQUERYPARAM tags - they just make the file size bigger!

On a more serious note (it can only get more serious from there), in working with Flex on a somewhat larger scale recently, we (developers here at MediFit) have found that the less logic you make Flex do, and the more you push that off onto the server, the happier your life will be! I can only assume the same for AIR (will find out soon)
# Posted By David | 1/20/09 10:04 AM
Eric's Gravatar Actually, you can set up (at least) SQL Server to accept REST queries... although I forget what MS calls it though -- uses the web server built into SQL Server.
# Posted By Eric | 1/21/09 1:48 AM
Jeffry Houser's Gravatar Eric,

Pretty cool; I don't think I knew that.

Whether this is a good idea or not is open to discussion, I suppose.
# Posted By Jeffry Houser | 1/21/09 8:26 AM
Andrew Westberg's Gravatar AIR has full access to the system. As such, it doesn't worry about checking any crossdomain.xml files (since it itself doesn't run on any domain).
# Posted By Andrew Westberg | 1/21/09 7:22 PM
Jeffry Houser's Gravatar William

That is exactly the project I was thinking of; thanks!

Andrew,

Thanks for the clarification on cross domain issues. I should have known that.
# Posted By Jeffry Houser | 1/21/09 8:02 PM
Patrick Whittingham's Gravatar I believe Oracle mod pl_sql gateway (Oracle 10g) allows direct call to a stored procedure.
# Posted By Patrick Whittingham | 1/26/09 9:12 AM
Tim Hoff's Gravatar The drawback to using URL queries for SQL-Server is that they are susceptible to SQL injection and don't have a security model in place.
# Posted By Tim Hoff | 4/22/09 11:10 PM
Jeffry Houser's Gravatar Tim,

If you're passing URL Queries to a middleware template (Such as a CFM page), that page can deal with validating the URL data to avoid SQL injection attacks.

I'm not too knowledgeable about calling SQL procedures / statements direct on the database via HTTP protocols, though. I can see how that could cause problem if no way to validate the data to protect the injection attacks.
# Posted By Jeffry Houser | 4/22/09 11:28 PM
Caleb Adam Haye's Gravatar Actually, you can do this by writing a custom socket. I have connected directly to news (NNTP) servers in the past, and the assql project on google code has a pretty good jump on a MySQL lib that is pure AS3

http://code.google.com/p/assql/source/browse/trunk...
# Posted By Caleb Adam Haye | 4/24/09 1:24 AM
Jeffry Houser's Gravatar Caleb,

That was in fact the project I was referring to in my post, and was linked to by William (another commenter).

I have the impression that SQL project was not production ready. I'm not sure I'd recommend using that in a production environment for that reason.
# Posted By Jeffry Houser | 4/24/09 1:38 AM
secho's Gravatar Hi, I use asSQL flex/air mysql framework and it works very well, althought it is still beta. I can say that this is reliable solution for smaller projects and believe it becomes production-use ready soon.
# Posted By secho | 5/5/09 7:40 PM
Arnold Aprieto's Gravatar I agree with Jeff. There is no way to connect a flex application or an air using action script.
You need to use a middleware.
Try this one for rubyonrails: http://www.adobe.com/devnet/flex/articles/flex2_ra...
# Posted By Arnold Aprieto | 8/6/09 7:11 PM
All Content Copyright 2005, 2006, 2007, 2008, 2009 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002.