문제

I am currently using Schemacrawler to gather information about various databases.

The issue I am having is that the user which the application runs under doesn't have access to every database. If I attempt to retrieve the list of schemas:

SchemaCrawlerOptions schemaCrawlerOptions = new SchemaCrawlerOptions();
schemaCrawlerOptions.setSchemaInfoLevel(SchemaInfoLevel.minimum());
schemaCrawlerOptions.setTableTypes(new TableType[] { TableType.table });

Database database = SchemaCrawlerUtility.getDatabase(connection, schemaCrawlerOptions);
database.getSchemas()

... a SchemaCrawlerException is thrown (The server principal "..." is not able to access the database "..." under the current security context.). Is there a way to get only the databases that are accessible (without having to explicitly declare each schema name)?

도움이 되었습니까?

해결책

From the exception you are getting, I am going to assume that you are using SQL Server. You need to set a schema inclusion rule. You can add this to your code snippet above:

schemaCrawlerOptions.setSchemaInclusionRule(new InclusionRule("schema_name.dbo.*", ""));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top