Skip to content

Commit cc9284d

Browse files
Backup sys.configurations call with sp_configure for under-privileged users
1 parent d83f05e commit cc9284d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -1015,15 +1015,19 @@ public int getMaxColumnsInTable() throws SQLServerException {
10151015
public int getMaxConnections() throws SQLException, SQLTimeoutException {
10161016
checkClosed();
10171017
try {
1018-
String s = "select maximum from sys.configurations where name = 'user connections'";
1019-
SQLServerResultSet rs = getResultSetFromInternalQueries(null, s);
1020-
if (!rs.next())
1021-
return 0;
1018+
SQLServerResultSet rs = getResultSetFromInternalQueries(null,
1019+
"select maximum from sys.configurations where name = 'user connections'");
1020+
if (!rs.next()) {
1021+
// Try with sp_configure if users do not have privileges to execute sys.configurations
1022+
rs = getResultSetFromInternalQueries(null, "sp_configure 'user connections'");
1023+
if (!rs.next()) {
1024+
return 0;
1025+
}
1026+
}
10221027
return rs.getInt("maximum");
10231028
} catch (SQLServerException e) {
10241029
return 0;
10251030
}
1026-
10271031
}
10281032

10291033
@Override

0 commit comments

Comments
 (0)