sql 2008 connection

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

sql 2008 connection

Post by bsouthuk » Tue Nov 18, 2014 1:58 pm

Hi

I am use to using mySQL when connecting to databases using livecode.

However, I now need to connect to a SQL2008 database... Is this possible with Livecode?

I am currently using the following code:

Code: Select all

on mouseUp
    -- use a global variable to hold the connection ID so other scripts can use it
    global gConnectionID
    
    -- set up the connection parameters - edit these to suit your database
    put "82.70.24.xxx" into tDatabaseAddress
    put "salesloxxx_xxx" into tDatabaseName
    put "saleslxxx_sxxxd" into tDatabaseUser
    put "saleslxxx_xxxxxx" into tDatabasePassword
    
    -- connect to the database
    put revOpenDatabase("mysql", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
    
    -- check if it worked and display an error message if it didn't
    -- & set the connection ID global
    if tResult is a number then
        put tResult into gConnectionID
        answer info "Connected to the database." & cr & "Connection ID = " & gConnectionID
    else
        put empty into gConnectionID
        answer error "Unable to connect to the database:" & cr & tResult
    end if
end mouseUp
Would connecting to a sql2008 database be similar? Any pointers or lesson links would be most appreciated.

Many thanks

Daniel

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: sql 2008 connection

Post by bangkok » Tue Nov 18, 2014 2:17 pm

bsouthuk wrote: Would connecting to a sql2008 database be similar? Any pointers or lesson links would be most appreciated.
l
Yes. But you need to connect through a ODBC datasource (that needs to be created first).

In Livecode, it would be then :

Code: Select all

 put revOpenDatabase("odbc", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: sql 2008 connection

Post by bsouthuk » Tue Nov 18, 2014 2:22 pm

Many thanks for your reply.

If the ODBC datasource is created, will I be able to access the database remotely as long as I have internet connection?

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: sql 2008 connection

Post by AxWald » Tue Nov 18, 2014 2:38 pm

Hi,

create a system dns on your machine, to the SQL server. Use this one in your connection, and it will work.

I you want to connect via Internet, be sure that, for the SQL server, port forwarding is enabled (on the router). Be careful with this - I'd not really want to have an SQL server exposed to the net directly! At least use some uncommon port - above 50000?

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Post Reply

Return to “Databases”