Hi smile,
To fetch the details from connection string from web.config file refer below code.
C#
protected void Page_Load(object sender, EventArgs e)
{
string constr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
System.Data.SqlClient.SqlConnectionStringBuilder connectionStringBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder(constr);
string ServerName = connectionStringBuilder.DataSource;
string DatabaseName = connectionStringBuilder.InitialCatalog;
string UserName = connectionStringBuilder.UserID;
string Password = connectionStringBuilder.Password;
string message = "Server Name : " + ServerName + "\\nDatabase Name : " + DatabaseName + "\\nUser Name : " + UserName + "\\nPassword : " + Password;
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('" + message + "')", true);
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim constr As String = System.Configuration.ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim connectionStringBuilder As System.Data.SqlClient.SqlConnectionStringBuilder = New System.Data.SqlClient.SqlConnectionStringBuilder(constr)
Dim ServerName As String = connectionStringBuilder.DataSource
Dim DatabaseName As String = connectionStringBuilder.InitialCatalog
Dim UserName As String = connectionStringBuilder.UserID
Dim Password As String = connectionStringBuilder.Password
Dim message As String = "Server Name : " & ServerName & "\nDatabase Name : " & DatabaseName & "\nUser Name : " & UserName & "\nPassword : " & Password
ClientScript.RegisterClientScriptBlock(Me.GetType(), "", "alert('" & message & "')", True)
End Sub
Screenshot