Is it possible to connection string declared in web config file and use in subpages of Master Page once it defined in master page....because I dont want to declare it again and again in sub pages because that again the same thing like declaring connection string locally like below on every subpage of Master Page
Public connStr As String = ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString
Public cn As New SqlConnection(connStr)
Public cmd As New SqlCommand
...plz help..
I Hope i am clear with my query

Iftikar HussainRank #423 · 5.9K reputationPosted Jul 29, 2013, 9:37 PM EDT
You no need to declare you connection string again and again until it is different for sub page. Just declare once in your main web.config
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 29, 2013, 9:38 PM EDT
http://www.aspdotnet-suresh.com/2011/11/write-connection-strings-in-webconfig.html
if you declare connection string in web.config you can access it any page within your project
Aman Jen136 reputationPosted Jul 29, 2013, 9:44 PM EDT
Can we write it as something like master page function after declaring in web.config file, to use like function in sub pages
Or in Function in Dll
I hope M clear
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 29, 2013, 9:49 PM EDT
then which page you want connection string !st add the reference
Imports System.Configuration
then you can able to get the connection string in page like this
Dim strcon As String = ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString
now you can use it
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 29, 2013, 9:50 PM EDT
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 29, 2013, 9:56 PM EDT
As iftikar said you create a Data access layer and get that connection string into that from web.config and use it in any page by creating object of that class.