Click here to Skip to main content
15,905,414 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I like to know their is any way to get all database names in oracle using c#. My requirement is to display all database names in oracle. Then i need to list all tables, procedures in each database. I know how to take tables in each database. But i do not know how to list all database names using c#. I am using oracle 9i server.
Posted
Updated 9-Dec-13 5:00am
v2

First, I'm assuming you mean all Schema's, not databases, this is oracle after all.

To select a list of schema's you can use this. But you need to have valid permissions for it.
SQL
SELECT * FROM dba_users;


Of course not all schema's have tables so another way is to use this

SQL
SELECT owner, table_name FROM dba_tables;


which will give you the 'schema' and all the table names for that schema.

you can use similar calls to get the procedures, functions, Packages and the column names, datatypes and sizes as well. All that data is stored in system tables.

SQL
SELECT Owner, Object_Name, Object_type, Status FROM ALL_OBJECTS WHERE OBJECT_TYPE IN ('FUNCTION','PROCEDURE','PACKAGE');
 
Share this answer
 
v2
Comments
Member 10455053 9-Dec-13 11:23am    
I think this is based on users and these users list belongs to any particular database. I like know their is any way to get all the database names or all the service names in oracle 9i in c# code.
bowlturner 9-Dec-13 11:46am    
In Oracle, each 'dba_user' in a specific database is a 'Schema' and can have tables and other DDL objects. Most databases have more 'users' than working schema's. The only way to get this from a database is Querying the database, this requires SQL.

In oracle different databases is a different thing and will need a separate connection for each one.
Sergey Alexandrovich Kryukov 9-Dec-13 11:24am    
5ed. Worse thing is: such code in not portable between different RDBMS...
—SA
bowlturner 9-Dec-13 11:28am    
right. I wrote code to compare Dev/Test/Prod databases on SQL server to look for changes in the DDL. But it was only useful for SQL Server...
Member 10455053 9-Dec-13 12:44pm    
So their is no way to get these database names? i created 2 database like http://docs.oracle.com/cd/B10501_01/win.920/a95491/create.htm
Why shouldn't you use Tnsnames.ora file and read it to identify the list of instances inside it?
You can find it under oracle_home/network/admin or your team might be using it from the share folder.

Please refer the link below just an example for a single db connection using tns entries.

http://www.oracle.com/technetwork/articles/dotnet/cook-dotnet-101788.html[^]
 
Share this answer
 
Comments
Member 10455053 9-Dec-13 20:53pm    
Actually my requirement is to select all database in a server. Then user can select any of that. Based on that selection need to create a connection string and display all tables and procedures. I do not know how to select all database names in oracle server.
KmgKrishnan 10-Dec-13 2:07am    
If i understand your requirement correctly, you wanted to have a feature how Toad/Sql developer lists the database. Once we select one and login, it connects to one database.

My idea is that you can check for the names within TNSNames.Ora file using Regex functions. I haven't tried in this case. I will check if i can bring some sample code.

In the mean time, please check the below links if it helps.

http://stackoverflow.com/questions/3004171/how-to-display-databases-in-oracle-11g-using-sqlplus

http://dba.stackexchange.com/questions/27725/how-to-see-list-of-databases-in-oracle

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900