0

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!

Asaf
  • 2,005
  • 7
  • 37
  • 59

3 Answers3

3

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.

Ralf de Kleine
  • 11,464
  • 5
  • 45
  • 87
2

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.

Habib
  • 219,104
  • 29
  • 407
  • 436
  • But it works when I try to run it... Also, the database is a remote mysql database, so there shouldn't be a problem connecting to it from another computer. – Asaf Jan 04 '13 at 12:23
  • 1
    @xTCx, implement some exception handling and logging in your application, Without it I don't think it will be easy to know what is going wrong. (if the framework is same as well). – Habib Jan 04 '13 at 12:24
1

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!

Asaf
  • 2,005
  • 7
  • 37
  • 59