Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightAggregationManager
This commit is contained in:
commit
683f8ac880
3 files changed
+119
-7
No files matched your search
@@ -119,6 +119,53 @@ namespace SunlightAggregationManager.UserClass
|
||||
return dataTable;
|
||||
}
|
||||
|
||||
public async Task<int> ExecuteQueryAsyncCount(string sql)
|
||||
{
|
||||
// 创建一个空的 DataTable 用于存放查询结果
|
||||
DataTable dataTable = new DataTable();
|
||||
|
||||
// 数据库连接字符串构建逻辑
|
||||
var builder = new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = DB_IP,
|
||||
InitialCatalog = DB_NAME,
|
||||
IntegratedSecurity = DB_TYPE == "Windows Authentication",
|
||||
TrustServerCertificate = true,
|
||||
ConnectTimeout = 5
|
||||
};
|
||||
|
||||
if (!builder.IntegratedSecurity)
|
||||
{
|
||||
builder.UserID = DB_ID;
|
||||
builder.Password = DB_PASSWORD;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using var conn = new SqlConnection(builder.ConnectionString);
|
||||
await conn.OpenAsync(); // 使用异步方式打开连接<websource>source_group_web_2</websource>
|
||||
|
||||
using (var cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
// 执行查询并将结果直接加载到 DataTable 中
|
||||
using (var reader = await cmd.ExecuteReaderAsync())
|
||||
{
|
||||
dataTable.Load(reader);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("DataBase Query failed\n" + ex.ToString());
|
||||
// 将异常抛出给调用方,或者返回一个空的 DataTable
|
||||
throw;
|
||||
}
|
||||
|
||||
return dataTable.Rows.Count;
|
||||
}
|
||||
|
||||
public void Database(string dat)
|
||||
{
|
||||
|
||||
|
||||
Reference in new issue
Block a user