473,503 Members | 7,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Console (exe) application crashes on open command (MySql)

38 New Member
Hi,
I have problem opening an MySql connection from an win console application. I am using SharpDevelop as IDE. Previously I've been working with MySql through C# aspx and am new to writing exe programs in C#, so I assume that I might be missing something in the IDE / project configuration.

I am successfully opening a connection and reading data from the table using adapter (window panel application binding to a grid), but when trying the code below in an console application the program crashes when calling the MyConn.Open(); function.

The error message being: Exception MySql.Data.MySqlClient.MySqlException was thrown in debuggee:
Unable to connect to any of the specified MySQL hosts.
Open()

If I break before the MyConn.Open(); function is called, the MyConn variable is filled with lot's of info looking ok to me, though I am not capable of knowing if any of it can tell me what leads to the crash in the next function call.
Ive added the MySql.Data.dll to the project from the GAC list in the add reference panel. Further, in addition to the references, I only have an AssemblyInfo.cs file and the Main.cs file with the code below in the project
I've reinstalled the MySql database trying different configurations etc, but whatever I have tried does not work.
Has anybody else encountered this problem and or know the solution?
Thanks in advance. The code follows below.
Expand|Select|Wrap|Line Numbers
  1. using MySql.Data.MySqlClient;
  2. using System;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Data;
  6.  
  7.  
  8. namespace VerPapConnCs
  9. {
  10.     class MainClass
  11.     {
  12.         public static void Main(string[] args)
  13.         {
  14.             string strProvider = "Database=VerPap;Data Source=localhost;User ID=root;Password=some";
  15.             MySqlConnection MyConn = new MySqlConnection(strProvider);
  16.             MyConn.Open();
  17.             string strSQL = "SELECT * FROM tab1;";
  18.             MySqlCommand mysqlCmd = new MySqlCommand(strSQL,MyConn);
  19.             MySqlDataReader mysqlReader = mysqlCmd.ExecuteReader();
  20.             while (mysqlReader.Read())
  21.             {
  22.                 Console.WriteLine(mysqlReader.GetInt32(0) + "\t" + mysqlReader.GetString(1));
  23.             }
  24.             MyConn.Close();
  25.         }        
  26.     }    
  27. }
  28.  
Sep 9 '08 #1
1 4781
elitesky
1 New Member
this post was old enough. but for the sake of new readers lyk me, ill try to place my opinion.

in strProvider string, i think you should explicitly specify the port, ex: port=3306
Dec 13 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1623
by: Fred Iannon | last post by:
All, I have developed an application that needs to run in one of two modes: (1) IF NO command line parms are provided I would like it to run as a Window form application (i.e. /target:winexe)...
1
5350
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
6
3222
by: Mark Allison | last post by:
Hi, I have an application that I want to be to run in Console mode and GUI mode. If no params are entered, I want the GUI fired up, if params are entered, then go into console mode. I believe...
11
29638
by: Peter Steele | last post by:
I have a Windows application written in C# that I want to return a non-zero exit code when it it run. The problem is that as a Windows application, there doesn't seem to be a way to control this....
17
4193
by: MumboJumbo | last post by:
Hi I have a really basic question hopefully some can help me with: Can you write a (i.e. one) C# project that works from the cmd line and gui? I seems if i write a GUI app it can't write to...
6
4873
by: vijai.kalyan | last post by:
Hello, I wrote a trivial program to set the console title in a console application. Here is the code:- namespace myns { class SetTitle { static void Main ( string args )
1
287
by: Allen Maki | last post by:
I would appreciate if someone helps me. I am reading a book called MS visual c++ .net step by step. I am using Visual C++ .net version 2003. I am trying to learn reading from file using...
4
10486
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
5
10759
by: =?Utf-8?B?SmFtZXMgV29uZw==?= | last post by:
Dear all, I'd like to know if there is any method to minimize command mode window when a console program is running. In my case, there are several console programs which run periodically in...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.