Blogs from
Welcome to Sign in | Join | Help
in Search

Ezequiel Espíndola's Blog

Connection String Settings In ASP.NET 2.0

There is a new configuration section for connection strings on ASP.NET 2.0 called <connectionStrings>. It is something so simple it seems dumb, but it helps to enforce recommended practices from the start. I really like this feature because of that.

In ASP.NET 1.x you could put your connection string anywhere you like it. It was normally on the web.config’s AppSettings section, but there wasn’t any enforcement from the framework on where to put it or how to retrieve it.

In ASP.NET 2.0 you can have all your connection strings on the <connectionStrings> section of the web.config, benefiting from centralized management and also enhanced security by encrypting them if you want.

    <add name="Pubs" connectionString="Server=(local);Integrated Security=True;Database=pubs;" providerName="System.Data.SqlClient" />

If you use these features, you can also make use of a new declarative expression that allows you to retrieve the Connection String by name and avoid hard-coding it on the page code.

This tag would retrieve the Connection String setup above by its name, “Pubs”:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
      ConnectionString="<%$ ConnectionStrings:Pubs %>" />

And you can also specify an expression for the ProviderName property of SqlDataSource:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Pubs %>"
ProviderName="<%$ ConnectionStrings:Pubs.ProviderName %>" />

Published Sunday, January 08, 2006 3:43 PM by eespindola
Filed Under: , ,
Anonymous comments are disabled

This Blog

Post Calendar

<January 2006>


Powered by Community Server, by Telligent Systems