i am executing a query but it doesnt work like i want to

Erdem Erdemir 1 Reputation point
2022-05-14T00:05:07.483+00:00

hi guys i am executing;
select name from sys.Databases
it only shows me system databases like master ect.
but i have lots of databases in my instance

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,642 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Jingyang Li 5,891 Reputation points
    2022-05-14T03:05:56.463+00:00

    You may have multiple instances on the same machine.
    Double check that you are running this query in your instance correctly.


  2. Erland Sommarskog 100.8K Reputation points MVP
    2022-05-14T06:29:05.983+00:00

    when i made this program i made users selecting the instance

    When i execute this query on ssms there is no problem it shows every database but when i use c# to do it it only shows system databases

    Debugging time, I guess!

    First add this query to your C# program:

       SELECT @@servername  
    

    to verify that you are connecting to the server you think you are connecting to.

    Would that be the case, then add this query:

       SELECT SYSTEM_USER, * FROM sys.fn_my_permissions(NULL, NULL)  
    

    Do you see VIEW ANY DATABASE in the list? Is the user the expected one?