5 Replies Latest reply on Apr 3, 2009 9:17 AM by Newsgroup_User

    Connecting to SQL Server

    apmyhr
      I need help connecting my Flex program to my MS SQL Server database (on my dev machine). I just don't know how to start. I just want to get simple CRUDQ. Does anyone have any advice?

      I have SQL Server 2008 Express. Visual Studio 2008 Web Developer Express and C# Express. I also have the trial version of LiveCycle Data Services ES. Is this all I need to build a connection?
        • 1. Re: Connecting to SQL Server
          Gregory Lafrance Level 6
          Try AMFPHP or just PHP for a quick connection. Flex by itself does not have database connectivity.
          • 2. Re: Connecting to SQL Server
            ice9_us
            this is what i have done..
            I didn't use php, but use C programs to connect to the database and spit out the select and insert type stuff in xml format... let me know if you need any sample code for the engine.
            • 3. Re: Connecting to SQL Server
              apmyhr Level 1
              Yes, sample code would be very appreciated. Thanks.
              • 4. Re: Connecting to SQL Server
                ice9_us Level 1
                here is the basic type deal.. If your not a C/C++ programmer I can give you more detail and working code.
                compile this put it in your cgi-bin directory and it should work.
                If you have issues i can help you out..
                I am a UNIX guy so if your running linux/solaris/hpux/aix something like that.. your in luck..
                if it is microsoft... i will have to fiddle a bit.

                #include <mysql.h>
                #include <stdio.h>

                main() {

                MYSQL *conn;
                MYSQL_RES *res;
                MYSQL_ROW row;
                char *sql_server = "servername/ip";
                char *sql_id = "mysqlid";
                char *sql_password = "mysqlpasswd";
                char *mysql_database = "database";
                int sql_return;
                char *cmd;

                printf("Content-type: text/xml\n\n");

                cmd=malloc(1024);
                sprintf(cmd, "select * from CPR_ticket where status != 'Closed';"); << put your mysql command here...


                conn = mysql_init(NULL);
                if (!mysql_real_connect(conn, sql_server, sql_id, sql_password, mysql_database, 0, NULL, 0)) {
                printf("Failed: %s\n", mysql_error(conn));
                }


                if (mysql_query(conn, cmd ) ) {
                printf("<result usr_name=\"mysql_error\" error_name=\"%s\" />\n", mysql_error(conn));
                mysql_free_result(res);
                mysql_close(conn);
                exit(1);

                }
                res = mysql_store_result(conn);


                if ( res != NULL ) { /* if you got something returned */
                if ( mysql_num_rows(res) > 0 ) {
                printf("<list>\n"); /* xml type tag... */
                for ( ; (row = mysql_fetch_row(res)) != NULL; ) {
                printf("<result key=\"%s\" number=\"%s\" sev=\"%s\" display=\"%s-%s-%s\" owner=\"%s\" />\n", row
                [0], row[1], row[2], row[0], row[2], row[1], row[3] );
                }
                printf("</list>\n"); /* end of xml type tag. */
                mysql_close(conn);
                mysql_free_result(res);
                exit(0);
                } else {
                printf("<result key=\"NoneFound\" />\n" );
                mysql_close(conn);
                mysql_free_result(res);
                exit(3);
                }
                }


                }
                • 5. Re: Connecting to SQL Server
                  Level 7

                  "ice9_us" <webforumsuser@macromedia.com> wrote in message
                  news:gr51s1$k9e$1@forums.macromedia.com...
                  > here is the basic type deal.. If your not a C/C++ programmer I can give
                  > you
                  > more detail and working code.

                  There's like a ton of ASP classic and ASP.net all over the web that shows
                  how to get data from a SQL Server database. You just need to find an
                  example that will return XML, then call your page from HTTPService.

                  Here's an example that you might find useful:

                  http://4guysfromrolla.com/webtech/041404-1.shtml