New topic: 

Unable to connect

<http://forums.realsoftware.com/viewtopic.php?t=47480>

         Page 1 of 1
   [ 7 posts ]                 Previous topic | Next topic          Author  
Message        ChrisTimm          Post subject: Unable to connectPosted: Tue 
Apr 02, 2013 8:16 am                         
Joined: Mon Mar 18, 2013 6:13 am
Posts: 10                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                DaveS          Post subject: 
Re: Unable to connectPosted: Tue Apr 02, 2013 8:26 am                           
      
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4717
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
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                ChrisTimm          Post 
subject: Re: Unable to connectPosted: Tue Apr 02, 2013 8:29 am                  
       
Joined: Mon Mar 18, 2013 6:13 am
Posts: 10                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                ChrisTimm          Post 
subject: Re: Unable to connectPosted: Tue Apr 02, 2013 8:33 am                  
       
Joined: Mon Mar 18, 2013 6:13 am
Posts: 10                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                DaveS          Post subject: 
Re: Unable to connectPosted: Tue Apr 02, 2013 8:47 am                           
      
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4717
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
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                ChrisTimm          Post 
subject: Re: Unable to connectPosted: Tue Apr 02, 2013 9:00 am                  
       
Joined: Mon Mar 18, 2013 6:13 am
Posts: 10                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                DaveS          Post subject: 
Re: Unable to connectPosted: Tue Apr 02, 2013 9:05 am                           
      
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4717
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
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 7 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to