go to start-->Run-->regedit Registory editor opens..
right click on Software and to add new key by name Myproject..(right click software new->key)
then go to Myproject and rightclick to add new key by name proj01(same as above)
after creating the proj01 key ..right click on the right pane to add a string value..to do that
right click on right pane new->string value
here the connection string can be specified in the string value in the "data" column and name as "ConnKey"
" server=192.110.210.34;database=MyDatabase;uid=user01;pwd=user01; "
==============================================================================================
go to web.config
in <appSettings> section write the folowing code
<appSettings>
<add key="RegistryPath" value="SOFTWARE\MyProject\Proj01"/>
</appSettings>
to get the connection string from the registry path
=====================================================
public static string GetConnectionString()
{
string ConnString = string.Empty;
RegistryKey regPath = Registry.LocalMachine.OpenSubKey(ConfigurationManager.AppSettings["RegistryPath"].ToString(), false);
try
{
if (regPath != null)
{
ConnString = regPath.GetValue("ConnKey").ToString();
}
else
{
throw new Exception("Error in establishing Connection with the DataBase");
}
}
catch (Exception e)
{
throw e;
}
return ConnString;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment