Database query error

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Scoperzor
Posts: 78
Joined: Tue Jan 27, 2015 1:10 pm

Database query error

Post by Scoperzor » Tue Jan 27, 2015 1:21 pm

I'm following this guide: "Scripting Database Access in LiveCode Stacks" on the livecode.byu website.

Trying to connect to an ODBC source (Microsoft SQL).

I have successfully connected and confirmed the connID is a number:

Code: Select all

   put revOpenDatabase("ODBC","ETMDataHub","ETMDataHub","x","x") into connID
   if connID is null then
      answer "Not connected"
   else
      answer "Connected" 
      end if
But when I try to do a query I get "invalid connection ID":

Code: Select all

 put "select * from tbl_Import_ZA_CPI" into tQuery
   put revDataFromQuery(tab,return,connID,tQuery) into tData
   put tData into field 'Result'
I have set up the ODBC source in Windows and the test is successful when I try connect to it there.

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Database query error

Post by MaxV » Tue Jan 27, 2015 1:29 pm

Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Scoperzor
Posts: 78
Joined: Tue Jan 27, 2015 1:10 pm

Re: Database query error

Post by Scoperzor » Tue Jan 27, 2015 1:30 pm

MaxV wrote:Did you read this: ...
Yes, I have done all of that. Most of my code was taken from that page too.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Database query error

Post by Klaus » Tue Jan 27, 2015 1:41 pm

HI Scoperzor,

1. welcome to the forum! :D
2. did you make sure that connID is either a LOCAL or GLOBAL variable?


Best

Klaus

Scoperzor
Posts: 78
Joined: Tue Jan 27, 2015 1:10 pm

Re: Database query error

Post by Scoperzor » Tue Jan 27, 2015 2:00 pm

Klaus wrote:HI Scoperzor,

1. welcome to the forum! :D
2. did you make sure that connID is either a LOCAL or GLOBAL variable?


Best

Klaus
Thank you for the welcome. Does it matter if it is local or global? I didn't previously declare it as either, but when trying to now, it still seems to give me the same error. I'm not whether I'm putting it in the correct place - if I declare it once by "global gconnID" in the first part of my script, should it work?

EDIT: All the code is on the same card, should this be necessary?

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Database query error

Post by Klaus » Tue Jan 27, 2015 2:12 pm

Hi Scoperzor,

global or local is a matter of whre you decalre and use the variables.

But as you said it is everything in the card script then you can declare the variable as local at the top of the compelte script,
so it can be used by all handlers in the script:

Code: Select all

local connID

on opencard
   ...
end opencard
etc...
Best

Klaus

Scoperzor
Posts: 78
Joined: Tue Jan 27, 2015 1:10 pm

Re: Database query error

Post by Scoperzor » Tue Jan 27, 2015 2:15 pm

Thanks, I actually figured it out just before you replied, your first suggestion together with one other change made it work :)

Post Reply