If I create a table with two columns: ID (int, Identity) and Database_name (NVARCHAR, MAX) and run your code, I do indeed get NULL, NULL.
But add two data rows:
ID Database_name
1 AAAA
2 AAAB
And I don't - I get an exception becuase it can't convert "AAAA" to an integer value.
If I replace the data with this:
ID Database_name
1 1111
2 1112
Then I get "reasonable" data:
(No column name) (No column name)
1113 1112
So your choice of column name is clearly wrong: you can't put a name in there.
And I can only replicate your failure when there are no rows - so start by checking your data.
But ... if you are using this to build a new database with sequential names each time you add some data, then that's probably a bad design. I'd strongly suggest that you rethink exactly why you decided this would be a good solution - both from a "why didn't I use an IDENTITY column?" POV, and a "why the heck do I need new databases at all, that's just silly" approach.