DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Fri, 03 Aug 2007 13:55:17 -0000,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    unknown
          2    Samuel R. Neff
                 3    Samuel R. Neff
          4    unknown


Web.config: connection string or connection key?   
Can someone explain the difference of using these functions below? And
what is the advantage/disadvantage of each?

        static public SqlConnection GetConnectionString(string
ConnectionStringName)
        {
            SqlConnection myConnection = new
SqlConnection(ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString);
            return myConnection;
        }

        static public SqlConnection GetConnectionKey(string
ConnectionKey)
        {
            SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings[ConnectionKey]);
            return myConnection;
        }

Rod
Date:Fri, 03 Aug 2007 13:55:17 -0000   Author:  

Re: Web.config: connection string or connection key?   
The first is more structure than the second.

The first syntax is the new ASP.NET 2.0 style of storing connection
info and is made specifically for connections.  It allows associating
connection strings and provider names with a named connection string.
This simplifies using the new provider factory model and programming
in a generic way so your code is not tied to a specific database.  In
both examples you use SqlConnection directly but you can and most
likely should be using DbConnection instead and that is more easily
accomplished with the first configuration method than the second.

Also the first method allows for storing encrypted connection strings
whereas the second does not (at least not without custom encryption
programming).

Additionally, the first will support the new management tools for
editing the Web.config better than the second (again, because it's
more structured).

HTH,

Sam

------------------------------------------------------------
We're hiring!  B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC.  Work with a variety of technologies
in a relaxed team environment.  See ads on Dice.com.



On Fri, 03 Aug 2007 13:55:17 -0000, rlueneberg@gmail.com wrote:


>Can someone explain the difference of using these functions below? And
>what is the advantage/disadvantage of each?
>
>        static public SqlConnection GetConnectionString(string
>ConnectionStringName)
>        {
>            SqlConnection myConnection = new
>SqlConnection(ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString);
>            return myConnection;
>        }
>
>        static public SqlConnection GetConnectionKey(string
>ConnectionKey)
>        {
>            SqlConnection myConnection = new
>SqlConnection(ConfigurationSettings.AppSettings[ConnectionKey]);
>            return myConnection;
>        }
>
>Rod
Date:Fri, 03 Aug 2007 11:44:09 -0400   Author:  

Re: Web.config: connection string or connection key?   
Samuel,   I don't understand how the first method is not tied to a
specific database if in both cases you can specify a connection name.
Can you give an example?

One more thing: if I wanted to use a more generic method called
GetDBConnection() what would be the best approach? I ask that because
they use the same string parameter.

Rod

On Aug 3, 11:44 am, Samuel R. Neff  wrote:

> The first is more structure than the second.
>
> The first syntax is the new ASP.NET 2.0 style of storing connection
> info and is made specifically for connections.  It allows associating
> connection strings and provider names with a named connection string.
> This simplifies using the new provider factory model and programming
> in a generic way so your code is not tied to a specific database.  In
> both examples you use SqlConnection directly but you can and most
> likely should be using DbConnection instead and that is more easily
> accomplished with the first configuration method than the second.
>
> Also the first method allows for storing encrypted connection strings
> whereas the second does not (at least not without custom encryption
> programming).
>
> Additionally, the first will support the new management tools for
> editing the Web.config better than the second (again, because it's
> more structured).
>
> HTH,
>
> Sam
>
> ------------------------------------------------------------
> We're hiring!  B-Line Medical is seeking .NET
> Developers for exciting positions in medical product
> development in MD/DC.  Work with a variety of technologies
> in a relaxed team environment.  See ads on Dice.com.
>
> On Fri, 03 Aug 2007 13:55:17 -0000, rlueneb...@gmail.com wrote:
> >Can someone explain the difference of using these functions below? And
> >what is the advantage/disadvantage of each?
>
> >        static public SqlConnection GetConnectionString(string
> >ConnectionStringName)
> >        {
> >            SqlConnection myConnection = new
> >SqlConnection(ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString);
> >            return myConnection;
> >        }
>
> >        static public SqlConnection GetConnectionKey(string
> >ConnectionKey)
> >        {
> >            SqlConnection myConnection = new
> >SqlConnection(ConfigurationSettings.AppSettings[ConnectionKey]);
> >            return myConnection;
> >        }
>
> >Rod
Date:Fri, 03 Aug 2007 18:37:01 -0000   Author:  

Re: Web.config: connection string or connection key?   
I'm sorry I wasn't clear when I said specific database I meant
database engine.  ADO.NET simplifies writing code that works with
MSSQL, MSAccess, Oracle, and any other database engine with an ADO.NET
provider.

A more generic example would be

ConnectionStringSettings info =
ConfigurationManager.ConnectionStrings["mydb"];

DbProviderFactory factory =
DbProviderFactories.GetFactory(info.ProviderName)

DbConnection cnn = factory.CreateConnection();
cnn.ConnectionString = info.ConnectionString;


The key point is that if you switch from MSSQL to Oracle or even from
MSSQL to MSSQL with a 3rd party provider (there are some) then you
don't have to change your code, just your config.

Doesn't help you if you have dbms-specific sql, but it's a good start.

HTH,

Sam

------------------------------------------------------------
We're hiring!  B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC.  Work with a variety of technologies
in a relaxed team environment.  See ads on Dice.com.


On Fri, 03 Aug 2007 18:37:01 -0000, rlueneberg@gmail.com wrote:


>Samuel,   I don't understand how the first method is not tied to a
>specific database if in both cases you can specify a connection name.
>Can you give an example?
>
>One more thing: if I wanted to use a more generic method called
>GetDBConnection() what would be the best approach? I ask that because
>they use the same string parameter.
>
>Rod
Date:Fri, 03 Aug 2007 17:37:21 -0400   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us