Your application should be designed to catch any errors that occur when it attempts
to connect to the database. The following code demonstrates how to catch an error
and display its message.
For C#:
try {
_conn = new AseConnection(
txtConnectString.Text );
_conn.Open();
}
catch( AseException ex ) {
MessageBox.Show(
ex.Message,
"Failed to connect");
}
For Visual Basic .NET:
Try
_conn = New AseConnection(_
txtConnectionString.Text)
_conn.Open()
Catch ex As AseException
MessageBox.Show(_
ex.Message,_
"Failed to connect")
End Try
Alternately, you can use the ConnectionString property to set the
connection string, rather than passing the connection string when the
AseConnection object is created.
For C#:
AseConnection conn = new AseConnection();
conn.ConnectionString = "Data Source='mango';" +
"Port=5000;" +
"UID='sa';" +
"PWD='';" +
"Database='pubs2';" ;
For Visual Basic .NET:
Dim conn As New AseConnection()
conn.ConnectionString = "Data Source='mango';" + _
"Port=5000;" + _
"UID='sa';" + _
"PWD='';" + _
"Database='pubs2';"
where “mango” is the name of the database server.