mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-20 18:47:55 +08:00
新增测试数据源
This commit is contained in:
@@ -61,17 +61,12 @@ namespace OpenAuth.App
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">数据源ID</param>
|
/// <param name="id">数据源ID</param>
|
||||||
/// <returns>是否连接成功</returns>
|
/// <returns>是否连接成功</returns>
|
||||||
public bool TestConnection(string id)
|
public bool TestConnection(TestConnectionReq req)
|
||||||
{
|
{
|
||||||
var obj = Repository.GetById(id);
|
|
||||||
if (obj == null)
|
|
||||||
{
|
|
||||||
throw new Exception("数据源不存在");
|
|
||||||
}
|
|
||||||
var conn = new SqlSugarClient(new ConnectionConfig()
|
var conn = new SqlSugarClient(new ConnectionConfig()
|
||||||
{
|
{
|
||||||
ConnectionString = obj.Connectionstring,
|
ConnectionString = req.Connectionstring,
|
||||||
DbType = (DbType)Enum.Parse(typeof(DbType), obj.Dbtype.ToString()),
|
DbType = (DbType)Enum.Parse(typeof(DbType), req.Dbtype.ToString()),
|
||||||
IsAutoCloseConnection = true,
|
IsAutoCloseConnection = true,
|
||||||
});
|
});
|
||||||
conn.Open();
|
conn.Open();
|
||||||
@@ -115,4 +110,6 @@ namespace OpenAuth.App
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record TestConnectionReq(string Connectionstring, int Dbtype);
|
||||||
}
|
}
|
@@ -56,6 +56,25 @@ namespace OpenAuth.WebApi.Controllers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//测试连接
|
||||||
|
[HttpPost]
|
||||||
|
public Response TestConnection([FromBody]TestConnectionReq obj)
|
||||||
|
{
|
||||||
|
var result = new Response();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_app.TestConnection(obj);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
result.Code = 500;
|
||||||
|
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//修改
|
//修改
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public Response Update([FromBody]AddOrUpdateExternalDataSourceReq obj)
|
public Response Update([FromBody]AddOrUpdateExternalDataSourceReq obj)
|
||||||
|
Reference in New Issue
Block a user