Re: Error -1811
Posted in 2004
Andrew Hardy wrote:
> Though I am sure it ought to be obvious to me, I think may be I am
> misunderstanding the term 'DATABASE statements' what to you mean,
In this context, a 'DATABASE statement' means, precisely, an SQL
statement that includes the keyword DATABASE:
DATABASE 'xyz;
CLOSE DATABASE;
CREATE DATABASE 'xyz';
DROP DATABASE 'xyz';
ROLLFORWARD DATABASE 'xyz'; -- SE only
START DATABASE 'xyz' ....; -- SE only
I think that's complete, which means I've probably forgotten a couple.
The term 'DATABASE statement' explicitly excludes any SQL statement
that is not in the list above (assuming that list is complete) - it
does not include SELECT, INSERT, DELETE, UPDATE, CREATE
<anything-but-database>, DROP <anything-but-database>, and so on.
> cannot I not do:
>
> CONNECT TO ...
>
> then do
>
> EXEC SQL etc etc
Of course, as long as 'etc etc' does not include one of the DATABASE
statements.
> I don't understand why not.
>
> Also what do you specifically mean by
>
> 'the CONNECT statement'
>
> Does this mean any kind of CONNECT.
I'm referring to EXEC SQL CONNECT TO ... in all its forms.
> I am using CONNECT TO ... AS ...,
> then from time to time I use SET CONNECTION
> to as I understand change the current connection.
There's no problem there. How you create the connection controls what
you can do; once you've got several connections, you can switch among
them as you see fit.
What is critical is that you can have an ESQL/C program with no
CONNECT statement; for example, one that reads:
int main(void)
{
EXEC SQL WHENEVER ERROR STOP;
EXEC SQL DATABASE 'xyz';
EXEC SQL CREATE TEMP TABLE t93(i INT NOT NULL);
...
return(0);
}
This creates an implicit connection to the database server - the
DATABASE statement creates an implicit connection. But, this program
could do things like 'EXEC SQL DROP DATABASE "pqr";' using that
connection, whereas if you wrote an explicit 'EXEC SQL CONNECT TO
"xyz";', the program would be unable to drop another database.
> A lot of the code is wrapped, so it's difficult to get to the boittom of
None of the code I sent was wrapped, AFAICS.
> it, but I think some of the scenarios is:
>
> CONNECT TO ... AS
>
> EXEC ...
> EXEC ...
> EXEC ...
>
> CONNECT TO ... AS
>
> get error -1811
No.
> ===================================
>
> CONNECT TO ... AS b
>
> EXEC ...
> EXEC ...
> EXEC ...
>
> SET CONNECTION TO c (some other previous connection)
>
> EXEC ...
> no error
>
> =======================================
>
> CONNECT TO ... AS b
>
> EXEC ...
> EXEC ...
> EXEC ...
>
> SET CONNECTION TO c (some other previous connection)
> SET CONNECTION TO c ... DORMANT
>
> EXEC ...
> error -1811
I don't think you get -1811 if you attempt to use a dormant
connection, but I'd stand to be corrected.
> ========================================
>
> CONNECT TO ... AS b
>
> EXEC ...
>
> begin
> EXEC ...
> EXEC ...
>
> SET CONNECTION TO c (some other previous connection)
This will fail unless you added WITH CONCURRENT TRANSACTIONS to the
original CONNECT statement.
> SET CONNECTION TO c ... DORMANT
>
> SET CONNECTION TO b
> EXEC ...
> EXEC ...
> end
> error -1811
Assuming you had the correct connection, then this would not be an error.
> ...Posting by Jonathan Leffler...
> Andrew Hardy wrote:
>
>>can somebody explain to me what this means:
>>
>>lesu273> finderr -1811
>>-1811 Implicit connection not allowed after an explicit connection.
>>
>>Once you have used the CONNECT TO statement to establish an explicit
>>connection to a database server, you cannot use one of the DATABASE
>>statements to connect implicitly to another database server. After an
>>explicit connection, you must use the CONNECT TO statement to connect
>>to other database servers.
>>
>>
>>If I have established an explicit connection to a db server, then surely
>>any using one of the databse statements after tha, must be asumed to be
>>sent to that server ?
>
>
> Yes, but did you connect to the server or to a specific database on
> the server?
>
> You can create an implicit connection like this:
> DATABASE 'joe@bloggs';
> You can also create an implicit connection like this:
> DATABASE 'joe';
>
> You can create an explicit connection to a database like this:
> CONNECT TO 'joe@bloggs';
> After this, you cannot use any of the DATABASE statements.
>
> You can create an explicit connection to a database server like this:
> CONNECT TO '@bloggs';
> And after this, you can do:
> CREATE DATABASE bill;> CLOSE DATABASE;
> DATABASE joe;> ...
> CLOSE DATABASE;
>
> And so on.
>
>>So why does the statement I execute think it is for a different server?
>
> The error message is clear - you are not allowed to create an implicit
> connection after you've made an explicit connection to a database.
>
> The expansion of the error message is not as clear as it could be.
> Better wording would be more like:
>
> Once you use the CONNECT statement to establish an explicit connection
> to a database, you cannot use any of the DATABASE statements when that
> is the current connection. You can use the notation CONNECT TO
> 'dbase@server' to connect to a different database, or the notation
> CONNECT TO '@server' to connect to a database server (after which, you
> can use the various DATABASE statements in that connection).
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/