19
Maximum number of used databases for each query has been exceeded. The maximum allowed is %d.
Adaptive Server has an eight-level-deep stack of open databases for each process. Every time a database is opened, it gets pushed onto the stack, and when it is closed, it is removed from the stack.
There is usually one open database for each process. If you run a query that uses a table in a different database, Adaptive Server opens that database just long enough to use the table and then closes the database.
Sometimes, however, a database must remain open longer. For example, if you execute a stored procedure in a different database than the one you are currently using, Adaptive Server will open that database and keep it open until the stored procedure finishes.
Only eight databases can be open at once. A single database opened multiple times is added to the stack each time it is opened. This can result in error 925, even though only one database has been used. If you have stored procedures that call other procedures in other databases, you can exceed this limit.
The use <database_name> command closes the database that was previously open, so error 925 would not be generated by eight use <database_name> commands in a row in Transact-SQL.
An example of a set of queries that exceeds the eight-level limit follows:
1> use db9 2> go
1> create proc pr9 2> as 3> select * from table1 4> go
1> use db8 2> go
1> create proc pr8 2> as 3> exec db9..pr9 4> go
1> use db7 2> go
1> create proc pr7 2> as 3> exec db8..pr8 4> go
1> use db6 2> go
1> create proc pr6 2> as 3> exec db7..pr7 4> go
1> use db5 2> go
1> create proc pr5 2> as 3> exec db6..pr6 4> go
1> use db4 2> go
1> create proc pr4 2> as 3> exec db5..pr5 4> go
1> use db3 2> go
1> create proc pr3 2> as 3> exec db4..pr4 4> go
1> use db2 2> go
1> create proc pr2 2> as 3> exec db3..pr3 4> go
1> use db1 2> go
1> create proc pr1 2> as 3> exec db2..pr2 4> go
Be aware of the eight-level open database limit when writing queries.
If you believe error 925 is occurring for a reason other than a query that has more than eight database openings, restarting Adaptive Server should clear the problem.
All versions