473,657 Members | 2,586 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.MySq lClient.MySqlEx ception 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 4790
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
1637
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) with a Main form, etc. and with execution returing to the command line AS SOON AS the program STARTS (2) If a command line parm IS provided I would
1
5377
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 application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component for this, and a test application for the component. It allows me to specify a command to execute,...
6
3232
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 I have all the code set up to do this, however when I issue a Console.WriteLine instruction, nothing gets written to the console. In fact, the command prompt comes back before the program has finished executing. What do I need to do?
11
29718
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. The value returned by the Main function has no impact on the value returned by the application. Windows applications exit immediately, leaving their windows still open. Is there a way to change the value a Windows application exits with. Basically...
17
4213
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 console using System.Console.WriteLine if thge project has its "Output Type" to "Windows Application". However I can write to stdio if i set output type to "Console Application". When I do this I unfortunately get a "console box" as well
6
4896
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 system::io. I have been asked to build the application, open a console window, change to the project's Debug directory, and run the program with a suitable command line, such as Cppfiles sa.
4
10502
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 doesn't seem to write to the screen in the way I would expect. The output is:
5
10767
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 server. Now, every console program instance will open a command mode window and they occupy the whole screen. I want to minimize all of them and maximize it if neccessary by manual. Is it possible and how to do it? I'm using VB.NET 2005. ...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7321
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1607
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.