Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Dec 18, 2018 12:46 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Unable to connect
PostPosted: Tue Apr 02, 2013 8:16 am 
Offline

Joined: Mon Mar 18, 2013 6:13 am
Posts: 11
I have written a URL manager simialr to the one in the getting started.

I am trying to save the information into the database and this is what I have in the window open


Dim db as New RealSQLDatabase
Dim dbFile as FolderItem


// Get database folder (This will install in the main folder)
dbFile = GetFolderItem("URLMANAGER.DB")
db.DatabaseFile = dbFile

if db.DatabaseFile.Exists = false then
if db.CreateDatabaseFile = false then
MsgBox "The database file was not created" + EndOfLine + _
CStr(db.ErrorCode) + " - " + db.ErrorMessage
exit
end if
db.SQLExecute ("create table URLlist (ID integer not null primary key, URL text)")
db.Commit
if db.Error then
MsgBox "The table was not created" + EndOfLine + _
CStr(db.ErrorCode) + " - " + db.ErrorMessage
exit
end if
end if




if db.Connect = false then
MsgBox "Could not connect to the database "
exit
end if



// Once the database is created then populate the list box

PopulateListBox


Then in the PopulatelistBox Method I have the following

Dim rs as recordSet
dim sql as String


lstURL.DeleteAllRows

sql = "Select * From URLlist"
rs = db.SQLSelect(sql)


if db.Error then
MsgBox "Error getting the recordset" + EndOfLine + _
CStr(db.ErrorCode) + " - " + db.ErrorMessage
end if




while not rs.EOF

lstURL.AddRow(rs.Field("URL").StringValue)
rs.MoveNext
Wend



rs.close


When I run this code I get the error saying the database is closed ? Not sure why as I have not closed the DB


Top
 Profile  
Reply with quote  
 Post subject: Re: Unable to connect
PostPosted: Tue Apr 02, 2013 8:26 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
this is your problem : dbFile = GetFolderItem("URLMANAGER.DB")

When your code is compiled it is one place, when it is in debug mode (in the IDE) it is probably in a BUILD folder.... search this forum and you will see this same problem mentioned many times.

Solution : put your database in the proper location. A location that does not change... and IS not next to the application.

I use "SpecialFolder.SharedDocuments" so that all users on the machine can access it.

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Unable to connect
PostPosted: Tue Apr 02, 2013 8:29 am 
Offline

Joined: Mon Mar 18, 2013 6:13 am
Posts: 11
This happens in Debug mode. i.e when I click the run button. I have tried to compile it, and it has the same error even though the database is there.


Top
 Profile  
Reply with quote  
 Post subject: Re: Unable to connect
PostPosted: Tue Apr 02, 2013 8:33 am 
Offline

Joined: Mon Mar 18, 2013 6:13 am
Posts: 11
Ok I dont think that is the problem. I have tried this.

Dim db as New RealSQLDatabase
Dim dbFile as FolderItem




#If DebugBuild Then
// DEBUG DATABASE
dbfile = SpecialFolder.Desktop.Child("Test_App_Database").Child("URLManager.DB")
#Else
// PRODUCTION DATABASE
dbfile = SpecialFolder.ApplicationData.Child("Test_App_Database").Child("URLManager.DB")
#Endif



db.DatabaseFile = dbFile

if db.DatabaseFile.Exists = false then
if db.CreateDatabaseFile = false then
MsgBox "The database file was not created" + EndOfLine + _
CStr(db.ErrorCode) + " - " + db.ErrorMessage
exit
end if
db.SQLExecute ("create table URLlist (ID integer not null primary key, URL text)")
db.Commit
if db.Error then
MsgBox "The table was not created" + EndOfLine + _
CStr(db.ErrorCode) + " - " + db.ErrorMessage
exit
end if
end if




if db.Connect = false then
MsgBox "Could not connect to the database "
exit
end if



// Once the database is created then populate the list box

PopulateListBox



And does the same when I run it


Top
 Profile  
Reply with quote  
 Post subject: Re: Unable to connect
PostPosted: Tue Apr 02, 2013 8:47 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
DO those paths exist?

If they do not, the dbfile will be NIL, in which case db.databasefile will not work.

Otherwise that code works just fine..... I tested in my iMac.. and it created the database, added the table, and connected
a second run, sucessfully connected.

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Unable to connect
PostPosted: Tue Apr 02, 2013 9:00 am 
Offline

Joined: Mon Mar 18, 2013 6:13 am
Posts: 11
Yes the paths exist.. I have manually created a folder on my desktop (Windows Machine) called "Test_App_Database" When I run the code the database gets created inside that folder (from the Window open event). If I open the database with a SQL Viewer I can see the datebase and browse to the tabels which got created. So from what i can see its physically there, but for some reason Real Studio does not think so .

Seems very bizarrre


Top
 Profile  
Reply with quote  
 Post subject: Re: Unable to connect
PostPosted: Tue Apr 02, 2013 9:05 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Like I said.... code works perfectly fine for me..... none of your error boxes pop up... and it gets all the way to your "populatelistbox" line....

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Unable to connect
PostPosted: Tue Apr 02, 2013 4:37 pm 
Offline

Joined: Mon Mar 18, 2013 6:13 am
Posts: 11
Thanks to all for help. I typed this all in again (Exactly the same mind you) and it now seems to work.. One of those bizarre things


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group