Open MooWeii opened 3 days ago
Prism注册的单例containerRegistry.RegisterInstance(fsql);
并且没有耗时的查询, 大部分都是在执行插入操作
如果只是这样定义 IFreeSql,在 3.2.833 这个版本上不会出现 【主库】Block access and wait for recovery: 错误。
FreeSql.dll FreeSql.Provider.SqlServer.dll
两处版本是否都是 3.2.833?
FreeSqlBuilder 完整的定义是什么?
这两个dll都是3.2.833的版本, FreeSqlBuilder完整定义就是上面写的那个, 只是把数据库名和用户密码隐去了, 下面是我完整的启动文件的代码, 在两个地方注入的FreeSql单例, 用到FreeSql的地方在下面给标出来了
// using ...
namespace MachineIOT
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : PrismApplication
{
ILogger logger = NLog.LogManager.GetCurrentClassLogger();
protected override Window CreateShell()
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
this.Dispatcher.UnhandledException += OnDispatcherUnhandledException;
var builder = new HostBuilder()
.UseServiceProviderFactory(new DryIocServiceProviderFactory(container: Container.GetContainer())) // 将默认的IoC容器用DryIoc接管
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseKestrel(o =>
{
o.ListenAnyIP(1883, l => { l.UseMqtt(); });
o.ListenAnyIP(7000); // 定义了默认的HTTP端口, 包括MQTT的socket提供端口和对外接口的端口
});
webBuilder.ConfigureServices(services =>
{
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
services.AddEndpointsApiExplorer();
//开始--------------------------------------------------------------------------------------------------------------------------------
services.AddSingleton(fsql); // webservice中注入FreeSql
//结束--------------------------------------------------------------------------------------------------------------------------------
});
webBuilder.Configure(app =>
{
var mqttController = app.ApplicationServices.GetRequiredService<MqttController>();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapConnectionHandler<MqttConnectionHandler>(
"/mqtt",
httpConnectionDispatcherOptions => httpConnectionDispatcherOptions.WebSockets.SubProtocolSelector =
protocolList => protocolList.FirstOrDefault() ?? string.Empty);
endpoints.MapControllers();
});
app.UseMqttServer(server =>
{
server.ValidatingConnectionAsync += mqttController.ValidateConnection;
server.ClientConnectedAsync += mqttController.OnClientConnected;
server.InterceptingPublishAsync += mqttController.InterceptingPublish;
});
});
});
var host = builder.Build();
host.RunAsync();
return this.Container.Resolve<MainWindow>();
}
//开始-----------------------------------------------------------------------------------------------------------------------------------
IFreeSql fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.SqlServer, @"Data Source=.;User Id=xxx;Password=xxx;Initial Catalog=xxx;Encrypt=True;TrustServerCertificate=True;Pooling=true;Min Pool Size=4")
.Build();
//结束-----------------------------------------------------------------------------------------------------------------------------------
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
//开始-------------------------------------------------------------------------------------------------------------------------------------
#region 注册FreeSql单例
containerRegistry.RegisterInstance(fsql);
#endregion
//结束-------------------------------------------------------------------------------------------------------------------------------------
containerRegistry.RegisterForNavigation<MainWindow, MainWindowViewModel>();
// 其他服务注册
PrismContainerExtension.Current.RegisterServices(s =>
{
s.AddHostedMqttServer(
optionsBuilder =>
{
optionsBuilder.WithDefaultEndpoint();
}
);
s.AddMqttConnectionHandler();
s.AddConnections();
s.AddSingleton<MqttController>();
});
}
protected override void OnInitialized()
{
var service = App.Current.MainWindow.DataContext as IConfigureService;
if (service != null)
{
service.SetUp();
}
base.OnInitialized();
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject as Exception;
logger.Error(ex.Message + " 详细信息: " + ex.StackTrace);
if (e.GetType() != typeof(System.Windows.Threading.DispatcherUnhandledExceptionEventArgs))
{
Environment.Exit(0);
}
}
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
logger.Error(e.Exception.Message + " 详细信息: " + e.Exception.StackTrace);
e.Handled = true;
if (e.GetType() != typeof(System.Windows.Threading.DispatcherUnhandledExceptionEventArgs))
{
Environment.Exit(0);
}
}
}
}
Connection Timeout Expired. The timeout period elapsed during the post-login phase. The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=0; handshake=2579; [Login] initialization=0; authentication=0; [Post-Login] complete=12673;
google 找这个错误的原因。
问题描述及重现代码:
程序运行一段时间就会报错, 有时候一天遇到一回, 有时候几天遇到一回, 看着是因为连接登录时候握手的原因, 但我用的本地的登录应该不存在网络的波动, 连接池也没满, 初次使用C#, 可能问题有点低级, 望能够解答
数据库版本
Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64)
安装的Nuget包
FreeSql 3.2.833 FreeSql.Provider.SqlServer 3.2.833
.net framework/. net core? 及具体版本
.Net8 具体为8.0.303