|
-
July 2nd, 2009, 11:35 AM
#5
Re: Problems connection to MySql database (remote)
I get this -
'A error occured while trying to connect to the server.
Unable to connect to any of the specified MySql hosts'.
I did all you said, except changing the string. It caused about 11 errors when i replaced the original string, so I just changed the words in the string, it now looks like this.
----------------------------------------------
string ConnectionString = "data source=student.dc.lincoln.ac.uk;database=08105199;Uid=u08105199;password=**********;";
#region Try to establish a connection to the database
MySqlConnection SQLConnection = new MySqlConnection();
try
{
SQLConnection.ConnectionString = ConnectionString;
SQLConnection.Open();
MessageBox.Show("Connection LeagueSQL database has been established.");
// You can get the server version
// SQLConnection.ServerVersion
}
catch (Exception Ex)
{
// Try to close the connection
if (SQLConnection != null)
SQLConnection.Dispose();
// Create a (useful) error message
string ErrorMessage = "A error occurred while trying to connect to the server.";
ErrorMessage += Environment.NewLine;
ErrorMessage += Environment.NewLine;
ErrorMessage += Ex.Message;
// Show error message (this = the parent Form object)
MessageBox.Show(this, ErrorMessage, "Connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
// Stop here
return;
}
#endregion
The references in use are these -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using MySql.Data;
using MySql.Data.Types;
using MySql.Data.MySqlClient;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|