Off to a flying start

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dalkin
Posts: 183
Joined: Wed Jul 04, 2007 2:32 am
Contact:

Off to a flying start

Post by dalkin » Sat Jan 22, 2011 12:01 pm

Hi there. I decided to forgo all my free time, alienate my friends and family - and start working with Rev and databases. So off to the tutorial at http://lessons.runrev.com/spaces/lesson ... L-database. The code at part 1 of the example returns:
Screen shot 2011-01-22 at 9.59.47 PM.png
Screen shot 2011-01-22 at 9.59.47 PM.png (10.2 KiB) Viewed 4932 times
Sorry, but I don't know enough to make it work. It's me, I know it's me. I'm using RevStudio 4.0.0
The underlying purpose of Al is to allow wealth to access skill
while removing from the skilled the ability to access wealth.

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

Re: Off to a flying start

Post by Klaus » Sat Jan 22, 2011 12:35 pm

Hi Dalkin,

looks like a syntax issue.
Could you please post the relevant part(s) of your script?

With a FAKE username and password of course 8)


Best

Klaus

dalkin
Posts: 183
Joined: Wed Jul 04, 2007 2:32 am
Contact:

Re: Off to a flying start

Post by dalkin » Sat Jan 22, 2011 10:35 pm

Hi Klaus,

As it happens, the code was a copy and paste from the tutorial with no changes - check out the link in my first post - you can see the code so I guess it's reproducible. I have no idea how the @% characters in the error message are being generated. To quote:

Create a new stack and drag over a new button from the Tools palette. use the Inspector to the button's name to "Connect" and copy the script below into its script.

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 "www.runrev.com" into tDatabaseAddress
put "test" into tDatabaseName
put "example" into tDatabaseUser
put "example" 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
The underlying purpose of Al is to allow wealth to access skill
while removing from the skilled the ability to access wealth.

robl
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 62
Joined: Wed Dec 22, 2010 9:50 pm

Re: Off to a flying start

Post by robl » Sun Jan 23, 2011 2:31 pm

It sounds like a MySQL grant (permissions) issue.

On MySQL servers, you must "grant" a database user @ hostname access to a specific database. This error is states that you connected to the database server, but the user 'example' has no permissions to the database 'test' when connecting from any machine. The '%' is a wildcard, representing ANY hostname/ip address.

I have never been able to connect to the demo database server listed in that lesson, so it could be that RunRev has disabled access to that public database. Or it could be the username/password is fictitious for illustrative use only, never intended to be used.

I suggest installing a copy of MySQL locally on either your development box or a dedicated machine. Another option is using a webhosting company, but many of those restrict from the outside world -- only the actual website being hosted is allowed access.

Once you have a locally running MySQL server, edit these lines in your script where tDatabaseAddress is set to IP address of the machine running MySQL server:

Code: Select all

-- set up the connection parameters - edit these to suit your database
put "192.168.1.4" into tDatabaseAddress  -- IP of machine running MySQL server
put "test" into tDatabaseName
put "example" into tDatabaseUser
put "example" into tDatabasePassword
Then you need to create the MySQL user. To do so, login to mysql as its 'root' user and issue something like this:

Code: Select all

CREATE USER 'example'@'%' IDENTIFIED BY 'example';
GRANT ALL ON test.* TO 'example'@'%';
Which says to create a user named 'example', connecting from any machine to be identified with the password 'example'. Then grant all permissions for database 'test' and all of its contents to the newly created example user.

Or to be more secure, you could GRANT restricted to specific client IP (the IP of the machine where your application is running):

Code: Select all

CREATE USER 'example'@'192.168.1.2' IDENTIFIED BY 'example';
GRANT ALL ON test.* TO 'example'@'192.168.1.2';
Sorry, but I don't know enough to make it work. It's me, I know it's me. I'm using RevStudio 4.0.0
I really don't think its you, in this case. The lesson seems vague, lacking anything explicitly stating the listed connection details can't be used, beyond the small blurb in the script comment.

dalkin
Posts: 183
Joined: Wed Jul 04, 2007 2:32 am
Contact:

Re: Off to a flying start

Post by dalkin » Sun Jan 23, 2011 10:43 pm

I ask for a crumb and you bring me a feast. Many thanks.
The underlying purpose of Al is to allow wealth to access skill
while removing from the skilled the ability to access wealth.

Post Reply