I am reading the book Pro ADO.net.
The author says that the <exename>.confi g files can store the connection string for security purposes.
Later he says that still the connection string is visible to it's better to encrypt it.
He explains that there is a new protectedData section in configuration files specifically for this purpose.
I created a DatabaseExercis e.vshost.exe.co nfig file and added the following code to it
Expand|Select|Wrap|Line Numbers
- <configuration>
- <connectionStrings>
- <EncryptedData/>
- </connectionStrings>
- <protectedData>
- <providers>
- <add name="MyProvider"
- type="System.Configuration.RsaProtectedConfigurationProvider
- keyContainerName="MyKeys"
- useMachineContainer="true" />
- </providers>
- <protectedDataSections>
- <add name="connectionStrings"
- provider="MyProvider"
- inheritedByChildren="false"/>
- </protectedDataSections>
- </protectedData>
- </configuration>
Expand|Select|Wrap|Line Numbers
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- config.ConnectionStrings.ConnectionStrings.Add(
- new ConnectionStringSettings(
- "MyConnectionString",
- "Provider=SQLNCLI.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Test;Data Source=(local)")
- );
- config.Save();
gets deleted !
The above was done in Visual studios.
And when i make a file DatabaseExercis e.exe.config file and run the DatabaseExercis e.exe file(found in debug folder) it throws an exception
Expand|Select|Wrap|Line Numbers
- 'MyKeys' is an unexpected token. Expecting white space. Line 9, position 19. (C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\DatabaseExercise\DatabaseExercise\bin\Debug\DatabaseExercise.vshost.exe.config line 9)
I am fed up by this.
I had also run aspnet_regiis -pc "MyKeys" exp .
Please help !