mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
* Uses MySQL Connector/NET from nuget * Adds SQL Server type to configuration. * Hostname for MySQL connections can include port - Format: <hostname>[:<port>] * Abstracted a bundle of stuff to be generic for both MSSQL and MySQL, including a number of variable and method names. (Mostly went from "sql..." -> "db..." * Changed MiscTools.DBDate() string building for MSSQL, uses DateTime.ToString() with a format which seemed simpler. * Unsure about which lines in .csproj are actually required, and which are auto-munged by Visual Studio. * ... This is my first C# (and VS!) work, be gentle! Signed-off-by: Mike Beattie <mike@ethernal.org>
42 lines
1.7 KiB
C#
42 lines
1.7 KiB
C#
using System;
|
|
using System.Data.SqlClient;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace mRemoteNG.Config.DatabaseConnectors
|
|
{
|
|
/// <summary>
|
|
/// A helper class for testing database connectivity
|
|
/// </summary>
|
|
public class DatabaseConnectionTester
|
|
{
|
|
public async Task<ConnectionTestResult> TestConnectivity(string type,
|
|
string server,
|
|
string database,
|
|
string username,
|
|
string password)
|
|
{
|
|
using (var dbConnector = DatabaseConnectorFactory.DatabaseConnector(type, server, database, username, password))
|
|
{
|
|
try
|
|
{
|
|
await dbConnector.ConnectAsync();
|
|
return ConnectionTestResult.ConnectionSucceded;
|
|
}
|
|
catch (SqlException sqlException)
|
|
{
|
|
if (sqlException.Message.Contains("The server was not found"))
|
|
return ConnectionTestResult.ServerNotAccessible;
|
|
if (sqlException.Message.Contains("Cannot open database"))
|
|
return ConnectionTestResult.UnknownDatabase;
|
|
if (sqlException.Message.Contains("Login failed for user"))
|
|
return ConnectionTestResult.CredentialsRejected;
|
|
return ConnectionTestResult.UnknownError;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return ConnectionTestResult.UnknownError;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |