为什么我的程序无法使用另一台具有访问数据库的计算机 [英] why my program not work another computer with access DataBase

查看:71
本文介绍了为什么我的程序无法使用另一台具有访问数据库的计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i用c#编写一个程序,它在我的笔记本电脑上工作非常好,当它与视觉工作室be然后我把它(exe文件和访问文件)转移到另一台计算机它不起作用



我的连接字符串:

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>





和decript代码:





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)
       {
           // Define the Dpapi provider name.
           string strProvider = "DataProtectionConfigurationProvider";
           // string strProvider = "RSAProtectedConfigurationProvider";

           System.Configuration.Configuration oConfiguration = null;
           System.Configuration.ConnectionStringsSection oSection = null;

           try
           {
               // Open the <span class="highlight">configuration</span> file and retrieve the connectionStrings section.

               // For Web!
               // oConfiguration = System.Web.Configuration.WebConfigurationManager.O  penWebConfiguration("~");

               // For Windows!
               // Takes the executable file name without the config extension.
               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;

                                   // Encrypt the section.
                                   oSection.SectionInformation.ProtectSection(strProvider);
                               }

                           }
                           else
                           {
                               if (oSection.SectionInformation.IsProtected)
                               {
                                   blnChanged = true;

                                   // Remove encryption.
                                   oSection.SectionInformation.UnprotectSection();
                               }
                           }
                       }

                       if (blnChanged)
                       {
                           // Indicates whether the associated <span class="highlight">configuration</span> section will be saved even if it has not been modified.
                           oSection.SectionInformation.ForceSave = true;

                           // Save the current <span class="highlight">configuration</span>.
                           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)

推荐答案

你改变了连接字符串吗?每台电脑都有不同的名称。



尝试检查程序文件夹中的app.config并在那里更改
did you change the connectionstring ? every computer have a difference Name.

try to check app.config in the program folder and change it there


您已经在笔记本电脑上加密了配置文件并且它只能在同一台计算机上解密。

要使它工作,你必须在目标计算机上加密它



可能你可以尝试自定义安装,祝你好运
You have encrypted the config file on your laptop and it can only be decrypted on same computer.
To make it work you have to encrypt it on target computer

May be u can try a custom installation to do this best of luck


这篇关于为什么我的程序无法使用另一台具有访问数据库的计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆