68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
|
using Api.Framework;
|
|||
|
using Api.Framework.Tools;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace DataDocking.Utils
|
|||
|
{
|
|||
|
public class SetConnectionConfig
|
|||
|
{
|
|||
|
public ConnectionConfig tempConfig = null;
|
|||
|
|
|||
|
public bool IsOk { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 测试mysql数据库是否可以链接
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
public string CheckMysqlLink(string host, string name, string user, string pass, string port)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
tempConfig = new ConnectionConfig();
|
|||
|
|
|||
|
tempConfig.ConnectionString = string.Format($"Data Source={host};Initial Catalog={name};Persist Security Info=True;User ID={user};Password={pass};Port={port};Min Pool Size = 5; Max Pool Size = 30;Charset=utf8;");
|
|||
|
tempConfig.DatabaseType = DatabaseType.MYSQL;
|
|||
|
var session = ApiClient.GetSession(tempConfig);
|
|||
|
session.BeginTransaction();
|
|||
|
session.Rollback();
|
|||
|
return string.Empty;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
tempConfig = null;
|
|||
|
return ex.Message;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 测试sqlite数据是否可以链接
|
|||
|
/// </summary>
|
|||
|
/// <param name="url"></param>
|
|||
|
/// <param name="pass"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public string CheckSqliteLink(string url, string pass = "")
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
string src = string.Format("Data Source={0};Version=3;password={1};Journal Mode=WAL;", url, pass);
|
|||
|
tempConfig = new ConnectionConfig() { ConnectionString = src, DatabaseType = DatabaseType.SQLITE };
|
|||
|
var session = ApiClient.GetSession(tempConfig);
|
|||
|
session.BeginTransaction();
|
|||
|
session.Rollback();
|
|||
|
return string.Empty;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
return ex.Message;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|