开发者

Get Oracle Database name

开发者 https://www.devze.com 2022-12-18 06:59 出处:网络
How can I programmatically g开发者_运维问答et the name of the Oracle database I am connecting to? I tried:

How can I programmatically g开发者_运维问答et the name of the Oracle database I am connecting to? I tried:

using (OracleConnection connection = new OracleConnection(oraConnectStr))
            {
                connection.Open();
                return connection.Database;
            }

but it returns empty string. I can't use the whole connection string because it may contain username/password.


Not every user has access to the V$ views. But everybody can run this:

SQL> select * from global_name
  2  /

GLOBAL_NAME
---------------------------------------------------
ORCL

SQL>

edit

If you want to solve this from inside c#, this article shows how to solve it through the ConnectionString.


you could query v$database:

SQL> SELECT NAME FROM v$database;

NAME
---------
PROD


You can use OracleConnectionStringBuilder object.

OracleConnectionStringBuilder connStrBuilder = new OracleConnectionStringBuilder(oraConnectStr);

connStrBuilder.DataSource will contain your information.

Check out: http://download.oracle.com/docs/html/E10927_01/OracleConnectionStringBuilderClass.htm#CHDHBCDA

0

精彩评论

暂无评论...
验证码 换一张
取 消