views:

346

answers:

4

I'm new to Flex and Adobe AIR, but I'm writing a desktop application that will need to connect and query commercial databases such as DB2, SQL Server and Oracle. How do I connect to these type of databases from ActionScript in an AIR application?

A: 

See my answer from this SO question: Database abstraction layer for AIR (JS)?

David Robbins
Thanks. Unfortunately, David, that doesn't support commercial databases.
Ophelia
A: 

AFAIK even air does not connect to a DB directly. You can however use ZendAMF (AMFPHP), SabreAMF, coldFusion, or any of several other ways to connect to DBs.

I personally use an HTTPService to call a php page that ouputs a query in XML.

There are so many ways to do this it would be hard to say what is right for you. Look up remoteObject and HTTPService example and find what's going to suit you best.

invertedSpear
A: 

I only know that it can connect directly to SQLite with Flex AIR. I know that the safari browser will have it's own datastore soon, so perhaps you can develop something in that vein.

joyceschan
+2  A: 

You really can't do it nicely, AIR is meant to use web servers as data sources not DBs, and there are no DB drivers in actionscript ready. That being said there are a few things that you can try:

  1. The usual way - you do not connect to a DB but ask a web server to do it for you, and return data
  2. Try this library - assql. It probably won't work very good, and it stopped being developed a year ago.
  3. With AIR 2.0 you can call native applications, so you could prepare an application that would do the queries for you and communicate with it. It will be rather complicated and if you're a beginner this probably makes no sense - and AIR 2.0 is still in beta. But you can even put a full blown Tomcat server inside an AIR 2.0 app, and after you do that you can use it like you would use a remote server. If you're interested read this post.

All in all, if you want to use DB-s as data sources AIR should probably not be your choice for a project.

Robert Bak
AIR 2.0 allows you to include and launch a native app, but you only communicate with it through stdin/stdout (at least that's what was said at the last Flash Camp I attended, is beta, so maybe it's changed). It would be really painful to do all your db communications this way.
Sam
That's true, but if you include a native app, which supports other means of communications (HTTP Requests, WebServices, etc.), than after launching it on the user pc you can communicate with it the way you communicate with regular web servers.
Robert Bak