Invalid connection id 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
rleiman
Posts: 56
Joined: Fri Dec 14, 2012 11:28 am
Location: Boston, MA
Contact:

Invalid connection id error

Post by rleiman » Fri Dec 14, 2012 11:36 am

Hi Everyone,

I'm using Mac OSX for the operating system.

I'm running a stack from lesson number 5 from the LiveCode Academy called "Simple Query Example" and it is giving the following error:

Code: Select all

invalid connection id
The only thing I changed was the specialFolderPath to where the database was as shown in this coding:

Code: Select all

local sDatabaseID

on preopencard
   put empty into field "details"
end preopencard

on connectToDatabase
   local tDatabasePath, tSQLQuery
   
   ## Connect to the database
   ## Save the connection id
   put specialFolderPath("emailaddresses.sqlite") into tDatabasePath
   put revOpenDatabase("sqlite",tDatabasePath,,,,) into sDatabaseID
end connectToDatabase

on displayDetails
   ## Query all details
   ## Put the result into the field
   put "SELECT * from contact_details" into tSQLQuery
   put revDataFromQuery(tab, return, sDatabaseID, tSQLQuery) into field "details"
end displayDetails
Since I'm new to the language, can you tell me what else I need to do to get it working?

I made sure the database was in the same location as the other files for this stack.

Thanks.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Invalid connection id error

Post by Klaus » Fri Dec 14, 2012 11:46 am

Hi rleiman,

well, "specialfolderpath()" is a function with FIXED parameters, please read up this term in hte dictionary!
You connot supply your own parameter 8)

So your line:
...
put specialFolderPath("emailaddresses.sqlite") into tDatabasePath
..
does not create a valid path and will give an error later.

Where exactly is your database "emailaddresses.sqlite" located?
You need to supply the full path to that db file in your "connection" script!


Best

Klaus

P.S
Welcome to the forum! :D

rleiman
Posts: 56
Joined: Fri Dec 14, 2012 11:28 am
Location: Boston, MA
Contact:

Re: Invalid connection id error

Post by rleiman » Fri Dec 14, 2012 4:24 pm

Thanks for the reply.

All files are in the same folder on my Mac.

I'm at work now so I can't tell you the exact path but it's off the main user folder in a folder called iosdevelopment.

If you can tell me how to proceed that will be appreciated.

Thanks.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Invalid connection id error

Post by Klaus » Fri Dec 14, 2012 4:43 pm

Hi rleiman,

so the stack and the db file are in the same folder?
Be sure to read up all terms in capitals in the dictionary! 8)

Then you could do something like this:
...
## 1. get the filename (0 path) to your stack
put the effective filename of this stack into tDatabasePath
## I use the "EFFECTIVE" keywords, since this will also work for substacks, which do not have a FILENAME of their own!
## this will result in something like this on my Mac
## -> /Applications/Revolution Enterprise/cool_stack.livecode

## 2. now set the ITEMDELIMITER to extract the "parent" folder from the name
## pathnames in Livecode always use the UNIX style SLASH as a pathdelimiter!
set itemdel to "/"

## 3. Instead of extracting the "parent" folder, we simply overwrite "cool_stack.livecode" with "emailaddresses.sqlite"
## in the last item of tDatabasePath and voila, the absolute path to your database file
put "emailaddresses.sqlite" into item last item of tDatabasePath
## -> /Applications/Revolution Enterprise/emailaddresses.sqlite
## Now tDatabasePath contains the correct path to your database file, ready to use
...

Best

Klaus

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

Re: Invalid connection id error

Post by bangkok » Fri Dec 14, 2012 4:48 pm

I think your problem is coming from :

Code: Select all

Local sDatabaseID
You declared it as... a local variable.

And then you use it in several handler.

It can't work.

In your script, at the top of it, put :
Global sDatabaseID
Then the content of sDatabaseID will be available to all your handlers (but be sure to remove all the other local sDatabaseID)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Invalid connection id error

Post by Klaus » Fri Dec 14, 2012 4:59 pm

Yes, but the main problem was: specialFolderPath("emailaddresses.sqlite") :D

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Invalid connection id error

Post by sturgis » Fri Dec 14, 2012 5:09 pm

Its declared as a script local, so all the handlers in that script should be fine with it that way. If other handlers are being called of course, then theres a problem, but my guess is that all the handlers are in the same script.
bangkok wrote:I think your problem is coming from :

Code: Select all

Local sDatabaseID
You declared it as... a local variable.

And then you use it in several handler.

It can't work.

In your script, at the top of it, put :
Global sDatabaseID
Then the content of sDatabaseID will be available to all your handlers (but be sure to remove all the other local sDatabaseID)

rleiman
Posts: 56
Joined: Fri Dec 14, 2012 11:28 am
Location: Boston, MA
Contact:

Re: Invalid connection id error

Post by rleiman » Sun Dec 16, 2012 2:53 pm

Thanks everyone for your replies and help.

I have it working now.

I originally thought that specialFolderPath was required for a database path since that was how it was shown in the tutorial. After reading your replies, I stuck in an "answer" statement to see what the actual path specialFolderPath was giving me and it was not where the database was located.

I looked at the properties of where I moved all of the files in finder and found out what the actual path was and included it like this statement:

Code: Select all

put "/Users/emad-ud-deenleiman/Development/iosdevelopment/CBT/ExampleStacks/emailaddresses.sqlite" into tDatabasePath

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Invalid connection id error

Post by Klaus » Sun Dec 16, 2012 2:58 pm

OK, but this absolute and hard-coded pathname will only work on your machine, I'm sure you know this! 8)

rleiman
Posts: 56
Joined: Fri Dec 14, 2012 11:28 am
Location: Boston, MA
Contact:

Re: Invalid connection id error

Post by rleiman » Sun Dec 16, 2012 6:30 pm

Hi,

Yes. I know. It's just for working with the tutorials and I will need to find out later how to do it for development on IOS. :mrgreen:

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”