Oracle 5.0 Reference Manual page 1918

Table of Contents

Advertisement

try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString;
conn.Open();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message);
}
You can also pass the connection string to the constructor of the
Visual Basic Example
Dim myConnectionString as String
myConnectionString = "server=127.0.0.1;" _
Try
Dim conn As New MySql.Data.MySqlClient.MySqlConnection(myConnectionString)
conn.Open()
Catch ex As MySql.Data.MySqlClient.MySqlException
MessageBox.Show(ex.Message)
End Try
C# Example
MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;
myConnectionString = "server=127.0.0.1;uid=root;" +
"pwd=12345;database=test;";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString);
conn.Open();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message);
}
Once the connection is open it can be used by the other Connector/Net classes to communicate with
the MySQL server.
20.2.5.2.2. Handling Connection Errors
Because connecting to an external server is unpredictable, it is important to add error handling to
your .NET application. When there is an error connecting, the
MySqlException
• Message: A message that describes the current exception.
• Number: The MySQL error number.
When handling errors, you can your application's response based on the error number. The two most
common error numbers when connecting are as follows:
• 0: Cannot connect to server.
• 1045: Invalid user name and/or password.
The following code shows how to adapt the application's response based on the actual error:
Connector/Net Programming
& "uid=root;" _
& "pwd=12345;" _
& "database=test;"
object. This object has two properties that are of interest when handling errors:
MySqlConnection
MySqlConnection
1898
class:
class will return a

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents