apache/seatunnel · error · RuntimeException
Couldn't obtain database name
Error message
Couldn't obtain database name
What it means
Thrown by SqlServerConnection when the query retrieving the current database name (GET_DATABASE_NAME via sys.databases/DB_NAME) fails with a SQLException. It wraps the driver error in a RuntimeException, typically during connector metadata initialization.
Source
Thrown at seatunnel-connectors-v2/connector-cdc/connector-cdc-sqlserver/src/main/java/io/debezium/connector/sqlserver/SqlServerConnection.java:884
}
/**
* Retrieve the name of the database in the original case as it's defined on the server.
*
* <p>Although SQL Server supports case-insensitive collations, the connector uses the database
* name to build the produced records' source info and, subsequently, the keys of its committed
* offset messages. This value must remain the same during the lifetime of the connector
* regardless of the case used in the connector configuration.
*/
public String retrieveRealDatabaseName(String databaseName) {
try {
return prepareQueryAndMap(
GET_DATABASE_NAME,
ps -> ps.setString(1, databaseName),
singleResultMapper(
rs -> rs.getString(1), "Could not retrieve exactly one database name"));
} catch (SQLException e) {
throw new RuntimeException("Couldn't obtain database name", e);
}
}
@Override
protected boolean isTableUniqueIndexIncluded(String indexName, String columnName) {
// SQL Server provides indices also without index name
// so we need to ignore them
return indexName != null;
}
@Override
public <T extends DatabaseSchema<TableId>> Object getColumnValue(
ResultSet rs, int columnIndex, Column column, Table table, T schema)
throws SQLException {
final ResultSetMetaData metaData = rs.getMetaData();
final int columnType = metaData.getColumnType(columnIndex);
if (columnType == Types.TIME) {View on GitHub (pinned to cf67b549a7)
Solutions
- Verify the configured database name exists and the login can connect to it directly
- Grant the login VIEW DEFINITION / catalog read permissions on the database
- Check SQL Server error logs and the wrapped SQLException for the exact cause
- Reconnect (fresh JdbcConnection) and retry if the connection was dropped
- If using an AG listener, retry after failover completes or connect to the primary replica
Example fix
// before
String db = connection.getDatabaseName(); // RuntimeException on any SQLException
// after
try {
String db = connection.getDatabaseName();
} catch (RuntimeException e) {
LOG.warn("db name lookup failed, retrying with fresh connection", e);
JdbcConnection fresh = dialect.openJdbcConnection(config);
String db = ((SqlServerConnection) fresh).getDatabaseName();
} Defensive patterns
Strategy: try-catch
Validate before calling
try (Connection c = DriverManager.getConnection(url, user, pass)) {
try (ResultSet rs = c.createStatement().executeQuery("SELECT DB_NAME()")) {
rs.next(); // throws here if permissions/context are wrong
}
} Try / catch
try {
String db = sqlServerConnection.getDatabaseName();
} catch (RuntimeException e) {
Throwable cause = e.getCause();
if (cause instanceof SQLException) { LOG.error("catalog query failed", cause); }
throw e;
} Prevention
- Grant the login catalog read permissions (VIEW DEFINITION) before starting the connector
- Use a direct connection to the primary replica, not a flaky listener, for metadata calls
- Validate the database name in config matches an existing database
- Check SQL Server error logs when metadata queries start failing
When it happens
Trigger: Calling the database-name lookup when the SQL Server connection is closed/broken, the login lacks permission to query the database catalog, or the database was dropped/renamed between connecting and the query.
Common situations: User without VIEW ANY DATABASE / insufficient catalog permissions; connecting to an availability-group listener during failover; wrong database name in config so DB_NAME() returns null context; network drop mid-query.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- Error to discover tables: ${e.getMessage()}
- Error to check tables: ${e.getMessage()}
- Read the binlog offset error
- Snapshotting of table ${table.id()} failed
- No result returned after running query [%s]
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/15228fd35d8fe9ec.
Report an issue: GitHub.