OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Making a connection to the database

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
leeand00
General User
General User


Joined: 01 Jul 2007
Posts: 24

PostPosted: Sun Jul 01, 2007 12:16 pm    Post subject: Making a connection to the database Reply with quote

When I execute the following code to open my database connection;

Code:
Sub testConnect

   Dim DatabaseContext As Object
   Dim DataSource As Object
   Dim Connection As Object
   Dim InteractionHandler As Object
   
   DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
   DataSource = DatabaseContext.getByName("job_db")
   
   If Not DataSource.IsPasswordRequired Then
      Connection = DataSource.GetConnection("","")
   Else
      InteractionHandler = createUnoService("com.sun.star.sdb.InteractionHandler")
      Connection = DataSource.ConnectWithCompletion(InteractionHandler)
   End If


End Sub


Line that causes the error
Code:

DataSource = DatabaseContext.getByName("job_db")


When the line above is executed I get the following error:



I'm using a mysql database which I connect to and definately works with Base, but it is also username and password protected.

Thank you,
Andrew J. Leer
Back to top
View user's profile Send private message
leeand00
General User
General User


Joined: 01 Jul 2007
Posts: 24

PostPosted: Mon Jul 02, 2007 9:05 am    Post subject: Ah HA! Reply with quote

It has something to do with the fact that I moved the file from one directory to another....somewhere inside the .odb file there is an absolute path name. Is there any way to fix this?
Back to top
View user's profile Send private message
leeand00
General User
General User


Joined: 01 Jul 2007
Posts: 24

PostPosted: Mon Jul 02, 2007 9:12 am    Post subject: Okay somebody told me what to do... Reply with quote

leeand00 asked:
Quote:

Hi, I just moved and .odb file from base to a diffrent directory and now when I try to run a macro which accesses a database it complains that it can't find the .odb file. Is there anyway to make the .odb file's path relative instead of absolute?


MechtiIDE Said:
Quote:

Register the new place under "Tools -> Options -> OpenOffice.org Base -> Databases"


And that fixed the problem.
Back to top
View user's profile Send private message
leeand00
General User
General User


Joined: 01 Jul 2007
Posts: 24

PostPosted: Mon Jul 02, 2007 10:07 am    Post subject: Just so people know what the error was: Reply with quote

Quote:

BASIC runtime error.
An exception occured
Type: com.sun.star.lang.WrappedTargetException
Message:
file:///C:/.../previous absolute path to .odb file
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Fri Jul 06, 2007 1:18 pm    Post subject: Reply with quote

what happens if you provide a direct URL to the Base document rather than the registered datasource name?
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group