hi
i write a program with c# and it work very good on my laptop when bebug it with visual studio now i transfer it (exe file and access file ) to an other computer it does not work
my connection string :
<connectionStrings>
<add name="Citybuilding" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Citybuilding.accdb;Jet OLEDB:Database Password=3051629170;"/>
</connectionStrings>
and decript code :
public class ReturnConnectionString
{
public static string ConnectionString
{
get
{
protection();
return ConfigurationManager.ConnectionStrings["Citybuilding"].ConnectionString;
}
}
public static void protection()
{
ToggleConnectionStringProtection(Application.ExecutablePath, true);
}
private static void ToggleConnectionStringProtection(string Path, bool Protect)
{
string strProvider = "DataProtectionConfigurationProvider";
System.Configuration.Configuration oConfiguration = null;
System.Configuration.ConnectionStringsSection oSection = null;
try
{
oConfiguration = System.Configuration.ConfigurationManager.OpenExeConfiguration(Path);
if (oConfiguration != null)
{
bool blnChanged = false;
oSection = oConfiguration.GetSection("connectionStrings") as System.Configuration.ConnectionStringsSection;
if (oSection != null)
{
if ((!(oSection.ElementInformation.IsLocked)) && (!(oSection.SectionInformation.IsLocked)))
{
if (Protect)
{
if (!(oSection.SectionInformation.IsProtected))
{
blnChanged = true;
oSection.SectionInformation.ProtectSection(strProvider);
}
}
else
{
if (oSection.SectionInformation.IsProtected)
{
blnChanged = true;
oSection.SectionInformation.UnprotectSection();
}
}
}
if (blnChanged)
{
oSection.SectionInformation.ForceSave = true;
oConfiguration.Save();
}
}
}
}
catch (System.Exception ex)
{
throw (ex);
}
finally
{
}
}
}
and error is :
Failed to decrypt using provider 'DataProtectionConfigurationProvider'. Error message from the provider: Key not valid for use in specified state. (Exception from HRESULT: 0x8009000B) (C:\Users\PC-01\Desktop\ShareFolder\New folder (3)\Citybuilding.exe.config line 12)/nSystem.Configuration/n at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.Configuration.GetSection(String sectionName)
at Citybuilding.Models.ReturnConnectionString.ToggleConnectionStringProtection(String Path, Boolean Protect) in d:\Project\Citybuilding\Citybuilding\Citybuilding\Models\ReturnConnectionString.cs:line 74
at Citybuilding.Models.ReturnConnectionString.protection() in d:\Project\Citybuilding\Citybuilding\Citybuilding\Models\ReturnConnectionString.cs:line 25
at Citybuilding.Models.ReturnConnectionString.get_ConnectionString() in d:\Project\Citybuilding\Citybuilding\Citybuilding\Models\ReturnConnectionString.cs:line 18
at Citybuilding.Models.ObjCityForm..ctor() in d:\Project\Citybuilding\Citybuilding\Citybuilding\Models\ObjCityForm.cs:line 46
at Citybuilding.Forms.frmControl.btnFind_Click(Object sender, EventArgs e) in d:\Project\Citybuilding\Citybuilding\Citybuilding\Forms\frmControl.cs:line 78/nSystem.Runtime.InteropServices.COMException (0x8009000B): Key not valid for use in specified state. (Exception from HRESULT: 0x8009000B)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at System.Configuration.DpapiProtectedConfigurationProvider.DecryptText(String encText)
at System.Configuration.DpapiProtectedConfigurationProvider.Decrypt(XmlNode encryptedNode)
at System.Configuration.ProtectedConfigurationSection.DecryptSection(String encryptedXml, ProtectedConfigurationProvider provider)
at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.DecryptSection(String encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedConfigSection)
at System.Configuration.Internal.DelegatingConfigHost.DecryptSection(String encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedConfigSection)
at System.Configuration.Internal.DelegatingConfigHost.DecryptSection(String encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedConfigSection)
at System.Configuration.BaseConfigurationRecord.CallHostDecryptSection(String encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedConfig)
at System.Configuration.BaseConfigurationRecord.DecryptConfigSection(ConfigXmlReader reader, ProtectedConfigurationProvider protectionProvider)