getting database name

  • Thread starter Thread starter Adi
  • Start date Start date
A

Adi

hi everyone... i have a doubt.. is there any way i can get the
database name.. my page is accessing.. i would like to display the
database name, the current page is accessing. This has to be done
without refering to the connection string which is usually used to
create the connection with the database. i would appreciate for the
help..
thanks
ADITYA
 
Hi there Adi,

two ways:

1.
string database = ((IDbConnection)myConnection).Database;

2.
SqlCommand command = new SqlCommand("SELECT DB_NAME();", connection);
string database = (string) command.ExecuteScalar();

or use SqlDataSource with SelectCommand property set to "SELECT DB_NAME()"

hope this helps
 
got it.. thanks milosz..

Hi there Adi,

two ways:

1.
string database = ((IDbConnection)myConnection).Database;

2.
SqlCommand command = new SqlCommand("SELECT DB_NAME();", connection);
string database = (string) command.ExecuteScalar();

or use SqlDataSource with SelectCommand property set to "SELECT DB_NAME()"

hope this helps
 
Back
Top