WPF application doesn't work in other computers

百般思念 提交于 2020-01-26 00:42:10

问题


I have built a simple WPF application just to gain some experience with it. 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.
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).

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.

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!).

What else could cause such problem? I really have no idea anymore...

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.
The solution can be found below...

Happy coding!


回答1:


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.




回答2:


Try using a Try Catch block surrounding your code inside the button event handler, like :

        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.




回答3:


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.

2) Set all of the above to Copy-Local.

3) Add the following lines to your App.config file:

  <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. 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. Mine was 6.5.4.0 which is the newest but older versions should work just as fine.

Also, I'd like to thank Ralf de Kleine and everyone else who answered for putting up/suggesting the exception code.
It was dumb of me to not think about using exceptions when they're just so convenient!



来源:https://stackoverflow.com/questions/14156971/wpf-application-doesnt-work-in-other-computers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!