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
Sanjeeb LenkaPosted Jul 30, 2013, 1:56 AM
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.
Iftikar HussainPosted Jul 30, 2013, 1:50 AM
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 30, 2013, 1:49 AM
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
Aman JenPosted Jul 30, 2013, 1:44 AM
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 LenkaPosted Jul 30, 2013, 1:38 AM
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
Iftikar HussainPosted Jul 30, 2013, 1:37 AM
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