新增测试数据源

This commit is contained in:
wintel
2025-03-15 20:36:05 +08:00
parent 3be8644769
commit 5664792162
2 changed files with 24 additions and 8 deletions

View File

@@ -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);
} }

View File

@@ -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)