views:

345

answers:

0

hi guys, i'm a totally newbie when it comes to the world of .net.

but what i'm trying to do here is to create a dll with some public functions which can be called by another program to access some data inside an password protected access database.

for now i'm keeping the password in the connection string and using the code below to encrypt the whole file.

// Retrieves a connection string by name.
        // Returns null if the name is not found.
        public static string GetConnectionStringByName(string name)
        {
            // Assume failure.

            string returnValue = null;

            // Look for the name in the connectionStrings section.
            ConnectionStringSettings settings =
                ConfigurationManager.ConnectionStrings[name];

            // If found, return the connection string.
            if (settings != null)
                returnValue = settings.ConnectionString;

            return returnValue;
        }

static void ToggleConfigEncryption(string exeConfigName)
        {
            // Takes the executable file name without the
            // .config extension.
            try
            {
                // Open the configuration file and retrieve 
                // the connectionStrings section.
                Configuration config = ConfigurationManager.
                    OpenExeConfiguration(exeConfigName);

                ConnectionStringsSection section =
                    config.GetSection("connectionStrings")
                    as ConnectionStringsSection;

                if (section.SectionInformation.IsProtected)
                {
                    // Remove encryption.
                    section.SectionInformation.UnprotectSection();
                }
                else
                {
                    // Encrypt the section.
                    section.SectionInformation.ProtectSection(
                        "DataProtectionConfigurationProvider");
                }
                // Save the current configuration.
                config.Save();

                Console.WriteLine("Protected={0}",
                    section.SectionInformation.IsProtected);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

however when i build the dll and test referencing it from another app, i can't get any information about the connection string.

can anyone lead me to any resources about this? i know there's probably a tons of stuff that i don't know and is doing wrong :) thanks