简体   繁体   English

WPF应用程序无法在其他计算机上运行

[英]WPF application doesn't work in other computers

I have built a simple WPF application just to gain some experience with it. 我建立了一个简单的WPF应用程序只是为了获得一些经验。 All it does is get information from a database when a user clicks on a button. 当用户单击按钮时,它所做的就是从数据库获取信息。
The application works fine in my PC(using the publish option), but when I tried running it on my laptop and my friends' PC, the app crashed as fast as the button was pressed. 该应用程序在我的PC上运行良好(使用publish选项),但是当我尝试在便携式计算机和朋友的PC上运行该应用程序时,该应用程序崩溃的速度与按下按钮一样快。
I'm 99% sure it has something to do with Entity Framework, which I use to contact the database (all the the function that gets fired on the button click does is contact and retrieve info from the DB). 我99%确信它与Entity Framework有关,我使用它来联系数据库(单击按钮时触发的所有功能都是联系并从数据库中检索信息)。

After looking for answers in google I found out that it may have something to do with either the .net installation in the PC, OR the project references. 在google中寻找答案后,我发现它可能与PC中的.net安装或项目参考有关。

However, the .net FW version is the same in my PC and my laptop, and the references were all marked as copy-local (just for testing!). 但是,.net FW版本在我的PC和笔记本电脑中是相同的,并且所有引用均标记为本地副本(仅用于测试!)。

What else could cause such problem? 还有什么可能导致这种问题? I really have no idea anymore... 我真的不知道了...

UPDATE UPDATE

Using exceptions, I found out that the error I got was: 使用异常,我发现我得到的错误是:
The specified store provider cannot be found in the configuration, or is not valid.

I also solved this problem by searching deeper in Google. 我还通过在Google中进行更深入的搜索来解决了这个问题。
The solution can be found below... 解决方案可以在下面找到...

Happy coding! 编码愉快!

All it does is get information from a database when a user clicks on a button. 当用户单击按钮时,它所做的就是从数据库获取信息。

In your application you are accessing a database via Entity Framework. 在您的应用程序中,您正在通过实体框架访问数据库。 I can only guess that your connection to the database is failing and because of that your application is crashing. 我只能猜测到您与数据库的连接失败,并且因此导致应用程序崩溃。 Make sure you have the database in place for the application. 确保已为应用程序准备好数据库。

Its also a good idea to log your exceptions so that you can view the details upon application crash. 记录异常也是一个好主意,这样您可以在应用程序崩溃时查看详细信息。

Try using a Try Catch block surrounding your code inside the button event handler, like : 尝试在按钮事件处理程序内使用围绕代码的Try Catch块,例如:

        try
        {
            //here your database logic

        }
        catch (Exception ex )
        {
            MessageBox.Show(ex.Message);
            //todo do something usefull
        }

This will give you information on why the application failed. 这将为您提供有关应用程序失败原因的信息。

I finally solved it! 我终于解决了!

This is how to do it: 这是怎么做的:
1) Make sure your project has a reference to MySql.Data.dll, MySql.Web.dll, MySql.Data.Entity.dll and System.Data.Entity.dll. 1)确保您的项目具有对MySql.Data.dll,MySql.Web.dll,MySql.Data.Entity.dll和System.Data.Entity.dll的引用。

2) Set all of the above to Copy-Local. 2)将以上所有设置为“本地复制”。

3) Add the following lines to your App.config file: 3) App.config添加到您的App.config文件中:

  <system.data>
  <DbProviderFactories>
    <clear />
    <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
    description=".Net Framework Data Provider for MySQL"
    type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, 
    Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  </DbProviderFactories>
</system.data>

4) Click on the MySQL.Data reference, and check it's version. 4)单击MySQL.Data参考,并检查其版本。 It can be found in the 'Properties' window below the solution explorer after you select it. 选择它后,可以在解决方案资源管理器下方的“属性”窗口中找到它。

5) Change the Version=6.4.4.0 part to the version of your MySql.Data.dll. 5)将Version=6.4.4.0部分更改为MySql.Data.dll的版本。 Mine was 6.5.4.0 which is the newest but older versions should work just as fine. 我的是6.5.4.0,这是最新版本,但较旧的版本应该可以正常工作。

Also, I'd like to thank Ralf de Kleine and everyone else who answered for putting up/suggesting the exception code. 另外,我还要感谢Ralf de Kleine和所有其他回答/建议异常代码的人。
It was dumb of me to not think about using exceptions when they're just so convenient! 我不愿意在异常方便时才考虑使用异常,这真是愚蠢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我将 c# windows 应用程序与 Access 数据库 (accdb) 连接,但该应用程序在其他计算机上不起作用 - I connected c# windows app with Access database (accdb) but the application doesn't work on other computers 多人游戏不适用于其他计算机。 只在同一个 - Multiplayer doesn't work with other computers. Only on the same one C#应用程序无法在其他计算机上运行 - C# app doesn't work in other computers 本地化WPF应用程序不起作用? - Localising a WPF application doesn't work? 安装后,带有 Access 数据库 (accdb) 的 c# windows 应用程序在其他计算机上不起作用 - The c# windows app with Access database (accdb) doesn't work on other computers after installation C#WPF应用程序UI在其他计算机上真的很慢 - c# WPF application UI really slow on other computers WPF应用程序在某些计算机上不起作用:停止工作错误 - WPF Application doesn't work on some machines: Stopped working error 将参数传递给另一个WPF应用程序不起作用 - Passing Arguments to another WPF Application doesn't work SignalR 不适用于 .net 内核 WPF 应用程序 - SignalR doesn't work with .net core WPF application WPF 应用程序无法使用自己的注册表项 - WPF application doesn't work with its own registry key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM