Click here to Skip to main content
14,770,081 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
registry values taken as wrong way in my c# code it is something early wrote values, my new connection string values not take into affect even though delete and recreate the registry key.

seperate winUI(windows application) was used to enter database name,pasword and username, it calls this application property class when saving and also this class called for connection string.




here is the code
/*
* Encryption
*/
using System;
using Microsoft.Win32;
using eSenze.SystemFramework.Common.Encryption;

namespace eSenze.SystemFramework.Common.ApplicationProperties
{
///
/// Provide the properties for the appliction.
///

public sealed class ApplicationProperty
{

private static string m_connectionString;

private static string m_gwGlobleConnectionString;
private static string m_gwDataConnectionString;
private static string m_gwDateFormat;
private static bool m_itergrationON;

private static string m_mailServer;
private static string m_dateFormat;
private static string m_fileName;
private static string m_generalMailFooter;
private static readonly string m_Key = "eSenze";

//public ApplicationProperty()
//{

//}
static ApplicationProperty()
{
//RegistryKey registryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\eSenze\\eHRMODEL");
//registryKey.SetValue("ConnectionString","wiGguALNyJO12uaRRquvbrYGSDorzltCHZakF0o6nVcE2KNvxXPTsta0qxcdT4i94KE/2dQuVUWgsNCeSSJ7v0SoZHbcHFT2EakDacAcA2xR0kjxm7IY/rLSFJHPu6TMs/m/SO+J0cad0VPUfUAmh2WVvvrNjaoxca+PJi3HegWyVDEEGMLgkhQo6xzeOubSO5BoYtzn/oYB6isPy+0PV9tzvmAFQNUrp8bHNDy4rY5URhdT7nbE2KlsZqnR4jzJ");
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\eSenze\\eHRM_AitkenSpence");
if(registryKey == null)
{
ApplicationProperty.SetRegistryValue();
}
else
{
object connectionString = registryKey.GetValue("ConnectionString");
object mailServer = registryKey.GetValue("MailServer");
object dateFormat = registryKey.GetValue("DateFormat");

object fileName = registryKey.GetValue("ServiceFileName");
object generalMailFooter = registryKey.GetValue("GeneralMailFooter");

object gwGlobleConnectionString = registryKey.GetValue("GWGlobleConnectionString");
object gwDataConnectionString = registryKey.GetValue("GWDataConnectionString");

object gwDateFormat = registryKey.GetValue("GWDateFormat");
object itergrationON = registryKey.GetValue("ItergrationON");
if(connectionString == null)
{
ApplicationProperty.SetRegistryValue();
}
else
{
try
{
CryptographyDotNetTripleDESEncryption cryptographyDotNetTripleDESEncryption = new CryptographyDotNetTripleDESEncryption();
m_connectionString = cryptographyDotNetTripleDESEncryption.Decrypt(connectionString.ToString(),m_Key);

CryptographyDotNetRijndaelEncryption cryptographyDotNetRijndaelEncryption = new CryptographyDotNetRijndaelEncryption();
m_gwGlobleConnectionString = cryptographyDotNetRijndaelEncryption.Decrypt(gwGlobleConnectionString.ToString(),m_Key);
m_gwDataConnectionString = cryptographyDotNetRijndaelEncryption.Decrypt(gwDataConnectionString.ToString(),m_Key);
}
catch
{
m_connectionString = string.Empty;
}

if(mailServer == null)
{
m_mailServer = string.Empty;
}
else
{
m_mailServer = mailServer.ToString();
}
if(dateFormat == null)
{
m_dateFormat = "MM/dd/yyyy";
}
else
{
m_dateFormat = dateFormat.ToString();
}

if(fileName == null)
{
m_fileName = "C:\\Inetpub\\wwwroot\\eHRMPCHWeb\\bin\\eHRMServiceProcess.exe";
}
else
{
m_fileName = fileName.ToString();
}
if(generalMailFooter == null)
{
m_generalMailFooter = "

Administrator
e-HRM System
Note: This is an e-HRM System generated email.
To Login the system Click here ";
}
else
{
m_generalMailFooter = generalMailFooter.ToString();
}

if(gwDateFormat == null)
{
m_gwDateFormat = "dd/MM/yyyy";
}
else
{
m_gwDateFormat = gwDateFormat.ToString();
}
if(itergrationON == null)
{
m_itergrationON = false;
}
else
{
m_itergrationON = Convert.ToBoolean(itergrationON);
}
}
}
}
private static void SetRegistryValue()
{
m_connectionString = "data source=local;persist security info=True;initial catalog=SLBC; UID = sa; PWD = 1234@com";
CryptographyDotNetTripleDESEncryption cryptographyDotNetTripleDESEncryption = new CryptographyDotNetTripleDESEncryption();
string encryptString = cryptographyDotNetTripleDESEncryption.Encrypt(m_connectionString,m_Key);
RegistryKey registryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\eSenze\\eHRM_AitkenSpence");
registryKey.SetValue("ConnectionString",encryptString);
registryKey.SetValue("DateFormat","MM/dd/yyyy");


}

public void SaveConnectionString(string serverMachineName,string database, string userName, string password)
{
m_connectionString = "data source=" + serverMachineName + ";persist security info=True;initial catalog=" + database + "; UID = " + userName + "; PWD = " + password;
CryptographyDotNetTripleDESEncryption cryptographyDotNetTripleDESEncryption = new CryptographyDotNetTripleDESEncryption();
string encryptString = cryptographyDotNetTripleDESEncryption.Encrypt(m_connectionString,m_Key);
this.SetRegistryValue("ConnectionString",encryptString);

}
public void SaveMailServer(string mailServer)
{
this.SetRegistryValue("MailServer",mailServer);
}
public void SaveDateFormat(string dateFormat)
{
this.SetRegistryValue("DateFormat",dateFormat);
}
private void SetRegistryValue(string key, string registryValue)
{
RegistryKey registryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\eSenze\\eHRM_AitkenSpence");
registryKey.SetValue(key,registryValue);
}

public void SaveServiceFileName(string fileName)
{
this.SetRegistryValue("ServiceFileName",fileName);
}
public void SaveGeneralMailFooter(string generalMailFooter)
{
this.SetRegistryValue("GeneralMailFooter",generalMailFooter);
}

public void SaveGWGlobleConnectionString(string fileName)
{
m_gwGlobleConnectionString = "Provider=VFPOLEDB.1;Data Source=" + fileName + ";Mode=Share Deny None;Extended Properties=\"\";User ID=\"\";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=MACHINE";//"data source=" + serverMachineName + ";persist security info=True;initial catalog=" + database + "; UID = " + userName + "; PWD = " + password;
CryptographyDotNetRijndaelEncryption cryptographyDotNetRijndaelEncryption = new CryptographyDotNetRijndaelEncryption();
string encryptString = cryptographyDotNetRijndaelEncryption.Encrypt(m_gwGlobleConnectionString,m_Key);
this.SetRegistryValue("GWGlobleConnectionString",encryptString);

}
public void SaveGWDataConnectionString(string fileName)
{
m_gwDataConnectionString = "Provider=VFPOLEDB.1;Data Source=" + fileName + ";Mode=Share Deny None;Extended Properties=\"\";User ID=\"\";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=MACHINE";//"data source=" + serverMachineName + ";persist security info=True;initial catalog=" + database + "; UID = " + userName + "; PWD = " + password;
CryptographyDotNetRijndaelEncryption cryptographyDotNetRijndaelEncryption = new CryptographyDotNetRijndaelEncryption();
string encryptString = cryptographyDotNetRijndaelEncryption.Encrypt(m_gwDataConnectionString,m_Key);
this.SetRegistryValue("GWDataConnectionString",encryptString);

}
public void SaveGWDateFormat(string dateFormat)
{
this.SetRegistryValue("GWDateFormat",dateFormat);
}
public void SaveIntergrationSwitch(string itergationMode)
{
this.SetRegistryValue("ItergrationON",itergationMode);
}
public static string ConnectionString
{
get
{
return m_connectionString;
}
}
public static string MailServer
{
get
{
return m_mailServer;
}
}
public static string DateFormat
{
get
{
return m_dateFormat;
}
}

public static string ServiceFileName
{
get
{
return m_fileName;
}
}
public static string GeneralMailFooter
{
get
{
return m_generalMailFooter;
}
}
public static string ReportHeader
{
get
{
return "MCB";
}
}

public static string HRMName
{
get
{
return "HR Manager";
}
}

public static string HRMDesignation
{
get
{
return "Manager - Human Resources";
}
}

public static string GWGlobleConnectionString
{
get
{
return m_gwGlobleConnectionString; //"Provider=VFPOLEDB.1;Data Source=D:\\GW\\GLOBAL\\dbGlobal.dbc;Mode=Share Deny None;Extended Properties=\"\";User ID=\"\";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=MACHINE";
}
}
public static string GWDataConnectionString
{
get
{
return m_gwDataConnectionString;
}
}
public static string GWDateFormat
{
get
{
return m_gwDateFormat;
}
}
public static bool GWItergrationOn
{
get
{
return m_itergrationON;
}
}
}
}




Posted
Updated 23-Jul-13 2:02am
v2
Comments
Sarin VT 23-Jul-13 6:22am
   
Please give a brief explanation. The question is incomplete.
Give some code parts if necessary.
renish patel 23-Jul-13 6:23am
   
Pls specify more details regrding it..
lakshmi from Sri Lanka 23-Jul-13 7:47am
   
pls can u help me
Sushil Mate 23-Jul-13 7:15am
   
please don't do it. do not post all the code here. not going to work.

All the registry related operations are explained in this codeproject article.
Please refer to it.
If you still have problem, please do include your code in the question.
Code Project Article
   
deleted all the published version of the application frm IIS. found all the registry refernces in the registry(using ctrl+f of the computer)and deleted all of them. rewrote to the registry,built the application and published.now it works fine
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900