Posted by: techsavygal | January 22, 2007

ASP.Net 2.0 changes…

Ofcourse, there will be changes from earlier versions for all products..but asp.net 2.0 has surpassed my expectations…

it has definitely eased programming , however, its getting more complicated…check out how to retrieve connectionstring from web.config file in your asp.net 2.0…Now ASP.net 2.0 allows storing multiple connection string elements within the ‘connectionStrings’ section in web.config.  This web.config section can be encrypted for security.  ConnectionStrings can be referred via Expressions which are resolved by ASP.Net Parser at run-time.  The ConnectionStrings stored in web.config sections can also be retrieved in your code at run-time by using the Configuration object. You will have to explicitly call OpenWebConfiguration() method for the same as shown below in the code sample:

//Retrieve ConnectionString from the web.config ConnectionStrings sectionSystem.Configuration.Configuration wsConfig;
string strConnectionString;
wsConfig System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(“/MyWebSite”
) ;

if (wsConfig.ConnectionStrings.ConnectionStrings.Count > )

{

    strConnectionString = wsConfig.ConnectionStrings.ConnectionStrings[“MyWebDBConnectionString”].ConnectionString;

}
else

{
    Throw New 
ApplicationException(“Could not connect to database”
);

}

This code would be useful if you want to retrieve a connectionstring from web.config for connecting to sql server database.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: