Resolved MySQL Connector works and then it doesn't.

muik

Member
Joined
Dec 3, 2009
Messages
13
Programming Experience
3-5
Hi,

I have developed some kind of "punch card" application for my office. Currently I am using textfiles to keep the data but I'd like to migrate it to our MySQL server.

I installed the .NET MySQL Connector and tried using it in my program. Here's the only code i'm adding and actually trying to make work:

Dim conn as new MySQLConnection("server=intranet;uid=myuserid;pwd=mypassword")
conn.Open

This code has been added after the "InitializeComponent" call of the startup window's constructor event, before anything actually tried to do something (i.e. i'm not even launching custom code at this place). Unfortunately, it generates an exception trying to "conn.Open" stating that it cannot find the server.

After much toying around with servers and firewalls and a lot of googling, I can't find a solution to my problem. Then I decide to try it in a new, blank application... So i create a new WPF application, copy/paste the code after the initial window's InitializeComponent... and it works!!!!! :confused:

And then I try again within my application and it doesn't. :eek:

Anyone has a tip? I tried adding all of my .xaml and .xaml.vb files manually to the blank project (the one where the conn.Open worked) and all of a sudden, it doesn't work anymore and I get the "cannot connect" message again. It seems as if something, somewhere, is preventing the MySQL Connector from working even though I'm not even going into my other .xaml and .xaml.vb files before trying the conn.Open call.

I'm totally clueless, and I'm about to rewrite the whole program from scratch just because of this. :mad: Any idea such as how to debug such a problem would be appreciated...

Thanks!
 
Last edited:
Wow... I just found *the* disturbing factor. Saving!

I create a new WPF project. I add a reference to MySQL.Data.MySQLClient and create the following code in Window_Loaded after adding a label named "InfoLabel":

Dim conn As New MySqlConnection("server=intranet;uid=myusername; pwd=mypassword")

Try
conn.Open()
InfoLabel.Content = "Connection Succeeded!"
Catch ex As MySqlException
InfoLabel.Content = "Connection Failed..."
End Try

When I hit F5, the label says "Connection Succeeded!".

Then I save the program by clicking the save icon and saving it to a default location.

Then I hit F5 again and the label says "Connection Failed..."... Then, there's no way I can make it connect again.

:confused::confused:
 
FIXED.

Apparently, something did not like the fact that I save my projects on a private network drive. I just moved the project folder to a local drive instead (good old C:) and it fixed the problem.

...go figure!!!!!!! :confused:
 
Back
Top