HOW CAN I SHOW THE DATABASE NAME TO MY VISITORS IN MVC4/RAZOR?

john rob

Total Post:108

Points:756
Posted by  john rob
 1282  View(s)
Ratings:
Rate this:
Hi Everyone!

I would like to inform my visitors of which database they are currently interacting with. My application only has a single Entity Framework connection 

string in it's web.config. The database name (initial catalog) is part of my connection string stored in my web.config.

I can expose the ENTIRE connection string in the shared layout by including the following html.

You are connecting to <span class="databasename">@System.Configuration.ConfigurationManager.ConnectionStrings

["MyConnectionStringName"].ConnectionString)</span>!
But I don't need the entire connection string only the database name. Is there a way to do this without involving a controller or instantiating a new 

SqlConnection()? Any suggestions?
of this given set.

Is my database bad designed? What would be the best way to do this or how to make the SELECT query

Thanks in advance!
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: How can I show the database name to my visitors in MVC4/Razor?

    Hi John!

    You can try this way

    @{
        var vDB = new System.Data.SqlClient.SqlConnectionStringBuilder(
            System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString)
        );
        var vName = vDB.InitialCatalog;
    }

    bind into span <span class="databasename">@vName</span>!


Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!