You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by John English <jo...@gmail.com> on 2011/05/02 15:13:16 UTC
Derby network server
I have a webapp which runs a networked Derby server. I want to be able
to access it from a separate app. The webapp starts the server from the
contextInitialized() method of a ServletContextListener:
server = new NetworkServerControl();
server.start(null);
which works fine. However, when I try to open a second connection with
IJ it gives me this response:
ij> connect '/foo/db;dataEncryption=true;bootPassword=xyz';
ERROR XJ040: Failed to start database '/foo/db', see the next
exception for details.
ERROR XSDB6: Another instance of Derby may have already booted the
database C:foo\db.
ij>
Is there something I'm missing here?
TIA,
------------------------------------------------------------------------
John English | My old University of Brighton home page is still here:
| http://www.it.brighton.ac.uk/staff/je
------------------------------------------------------------------------
Re: Derby network server
Posted by John English <jo...@gmail.com>.
On 03/05/2011 16:35, Bryan Pendleton wrote:
>> In the webapp:
>>
>> server = new NetworkServerControl();
>> server.start(null);
>
> Perhaps your webapp is trying to run these lines multiple times?
Nope, it does it from the context initialisation. It definitely
only happens once (various status things are logged at startup
which only get reported once).
> It can be very tricky to ensure that your webapp starts the
> Network Server once and only once. You may be starting it
> a second time, and the second instance is not succesfully
> accessing the database because the first instance already has
> the database open?
I'm starting it once from the webapp, then trying to connect
externally with IJ before I go any further.
------------------------------------------------------------------------
John English | My old University of Brighton home page is still here:
| http://www.it.brighton.ac.uk/staff/je
------------------------------------------------------------------------
Re: Derby network server
Posted by Bryan Pendleton <bp...@gmail.com>.
> In the webapp:
>
> server = new NetworkServerControl();
> server.start(null);
Perhaps your webapp is trying to run these lines multiple times?
It can be very tricky to ensure that your webapp starts the
Network Server once and only once. You may be starting it
a second time, and the second instance is not succesfully
accessing the database because the first instance already has
the database open?
A possibly simpler architecture for your application is to
have an entirely separate piece of software responsible for
starting/stopping the Network Server, and then it can concentrate
on doing that once-and-only-once. So:
1) Have a "Network Server" webapp
2) Have your normal application webapp(s), which access
the database as clients
3) Have your external command-line tool(s), which access
the database as clients
You can have as many (2) and (3) instances as you want; you
just have to ensure you have exactly one of your (1) instance.
thanks,
bryan
Re: Derby network server
Posted by John English <jo...@gmail.com>.
On 02/05/2011 20:53, Kristian Waagan wrote:
> Hi John,
>
> Looks to me like you are trying to access, or more specifically boot,
> the database with the embedded driver. This won't work since the network
> server has already booted the database [1].
> The only change required should be to add the host name to the
> connection URL (localhost?), i.e. something like
> "jdbc:derby://localhost[:port]/db[;attributes]". You will then get two
> (or more) connections to the database, all using the client driver and
> going through the network server.
Thanks for this (silly me!), but unfortunately it doesn't fix it.
In the webapp:
server = new NetworkServerControl();
server.start(null);
and then later:
conn = DriverManager.getConnection(
"jdbc:derby://127.0.0.1:1527/foo/db;dataEncryption=true"
+ ";bootPassword=xyz",
"app", "app");
which works fine -- the webapp accesses the DB and all is well.
But then I try connecting from IJ, and this is what I get:
ij> connect '//127.0.0.1:1527/foo/db;dataEncryption=true;bootPassword=xyz';
ERROR XJ040: DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ040, SQLERRMC:
Failed to start database 'foo/db' with class loader
WebAppClassLoader@Foo, see the next exception for details.::
SQLSTATE: XSDB6Another instance of Derby may have already booted
the database C:\Users\JE\Documents\Projects\foo\db.
ij>
So I'm still stuck... Any more ideas what I'm doing wrong here?
TIA,
------------------------------------------------------------------------
John English | My old University of Brighton home page is still here:
| http://www.it.brighton.ac.uk/staff/je
------------------------------------------------------------------------
Re: Derby network server
Posted by Kristian Waagan <kr...@oracle.com>.
On 02.05.11 15:13, John English wrote:
> I have a webapp which runs a networked Derby server. I want to be able
> to access it from a separate app. The webapp starts the server from the
> contextInitialized() method of a ServletContextListener:
>
> server = new NetworkServerControl();
> server.start(null);
>
> which works fine. However, when I try to open a second connection with
> IJ it gives me this response:
>
> ij> connect '/foo/db;dataEncryption=true;bootPassword=xyz';
> ERROR XJ040: Failed to start database '/foo/db', see the next
> exception for details.
> ERROR XSDB6: Another instance of Derby may have already booted the
> database C:foo\db.
> ij>
>
> Is there something I'm missing here?
Hi John,
Looks to me like you are trying to access, or more specifically boot,
the database with the embedded driver. This won't work since the network
server has already booted the database [1].
The only change required should be to add the host name to the
connection URL (localhost?), i.e. something like
"jdbc:derby://localhost[:port]/db[;attributes]". You will then get two
(or more) connections to the database, all using the client driver and
going through the network server.
Regards,
--
Kristian
[1] I'm assuming a connection to the database has already been made
through the network server. If you connect with the embedded driver
first, the connection through the network server will fail instead.
>
> TIA,
>
> ------------------------------------------------------------------------
> John English | My old University of Brighton home page is still here:
> | http://www.it.brighton.ac.uk/staff/je
> ------------------------------------------------------------------------