Person添加成员(ip)
项目目录修改
This commit is contained in:
1 parent
15313a5f75
commit
c2d15699ab
30 files changed
+3003
No files matched your search
@@ -0,0 +1,79 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using TouchSocket.Sockets;
|
||||
|
||||
namespace SunlightAggregationManager.UserClass
|
||||
{
|
||||
public class DataBase
|
||||
{
|
||||
private string DB_NAME = null!;
|
||||
private string DB_TYPE = null!;
|
||||
private string DB_ID = null!;
|
||||
private string DB_IP = null!;
|
||||
private string DB_PASSWORD = null!;
|
||||
|
||||
|
||||
public void Config(string ip, string name, string type, string id, string password)
|
||||
{
|
||||
DB_IP = ip;
|
||||
DB_ID = id;
|
||||
DB_NAME = name;
|
||||
DB_TYPE = type;
|
||||
DB_PASSWORD = password;
|
||||
|
||||
_= ConfigAsync();
|
||||
|
||||
}
|
||||
public async Task ConfigAsync()
|
||||
{
|
||||
await Task.Delay(3000);
|
||||
//进入后台线程操作
|
||||
await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// 构建连接字符串
|
||||
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;
|
||||
}
|
||||
|
||||
//连接数据库
|
||||
using var conn_SC = new SqlConnection(builder.ConnectionString);
|
||||
conn_SC.Open();
|
||||
using (var cmd = new SqlCommand("SELECT 1", conn_SC))
|
||||
{
|
||||
cmd.ExecuteReader();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("DataBase Link timeout\n"+ex.ToString());
|
||||
// 失败处理
|
||||
return; // 直接返回,不执行后续代码
|
||||
}
|
||||
Console.WriteLine("DataBase Link succeed");
|
||||
});
|
||||
}
|
||||
|
||||
public void Database(string dat)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user