It is a good idea to put connection string into connectionStrings section of Web.Config:
<connectionStrings>
<add name="MyConnectionString" connectionString="Integrated Security=SSPI;Initial Catalog=pubs;Data Source=(local);"/>
</connectionStrings>
Then you can easily read it from your application:
string connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
If you want to encrypt your connectionStrings section:
1) Copy Web.Config file into C:\Inetpub\wwwroot\MyWebSite folder.
2) Execute the following command:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -pe "connectionStrings" -app "/MyWebSite" -prov "DataProtectionConfigurationProvider"
If command from #2 was successfully executed, your ConnectionStrings section in C:\Inetpub\wwwroot\MyWebSite\Web.Config file is encrypted.
You still can use the same command in order to access your connection string:
System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
VS.NET 2005, C#, ASP.NET 2.0
Tuesday, October 18, 2005
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment