I have written in program in C# which connects to a MySQL database.
public bool Connect()
{
bool OK = true;
try
{
dbcon = new MySqlConnection(ConnectionString);
dbcon.Open();
}
catch
{
OK = false;
}
return OK;
}
For the connection string I am using
public string Server = "localhost";
public string Database = "samplemonitor";
public string UserID = "root";
public string Password = "password";
public bool Pooling = false;
public string ConnectionString
{
get
{
string isPooling;
if (Pooling)
{
isPooling = "true";
}
else
{
isPooling = "false";
}
return string.Format
(
"Server={0};Database={1};User ID={2};Password={3};Pooling={4}",
Server,
Database,
UserID,
Password,
isPooling
);
}
}
When I run this in debug mode in mono, the program hangs on the dbcon.Open(); command
However, when I run this program from outside the debugger, everything works fine.
EDIT
Trying Vinicius' Suggestion, to use "Data Source"
I end up with an error message
e=11001, NativeErrorCode=11001. ---> System.Net.Sockets.SocketException: No such host is known
at System.Net.Dns.GetAddrInfo(String name)
at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
at System.Net.Dns.GetHostEntry(String hostNameOrAddress)
at MySql.Data.Common.StreamCreator.GetDnsHostEntry(String hostname)
--- End of inner exception stack trace ---
at MySql.Data.Common.StreamCreator.GetDnsHostEntry(String hostname)
at MySql.Data.Common.StreamCreator.GetHostEntry(String hostname)
at MySql.Data.Common.StreamCreator.GetStreamFromHost(String pipeName, String hostName, UInt32 timeout)
at MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout)
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlConnection.Open()
at SampleMonitor.LocalDatabaseConnection.Connect() in c:\Dev\Repositories\HD-CMC\trunk\C#\SampleMonitor\SampleMonitor\Control\LocalDatabaseConnection.cs:line 394
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> System.Exception: Call to GetHostEntry failed after 00:00:00 while querying for hostname 'samplemonitor': SocketErrorCode=HostNotFound, ErrorCode
Its interesting that it did not hang on the open command this time
EDIT
This is very strange, it just decided to start working. I haven't changed any of the code. Could this be some kind of temperamental bug in Mono??