<ItemGroup> <PackageReference Include="SqlSugarCore" Version="5.1.3.52" /> </ItemGroup>
中文提示: BulkCopy MySql連接字串需要新增AllowLoadLocalInfile=true; 新增後如果還不行Mysql資料庫執行一下SET GLOBAL local_infile=1
English Message : connection string add : AllowLoadLocalInfile=true
show global variables like 'local_infile'; SET GLOBAL local_infile=1
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace WebApplication3 { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton<ISqlSugarClient>(s => { SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig() { DbType = SqlSugar.DbType.MySql, ConnectionString = "Server=192.168.31.132;User ID=root;Password=123456;Database=sugar;port=3306;AllowLoadLocalInfile=true", IsAutoCloseConnection = true, }, db => { //单例参数配置,所有上下文生效 db.Aop.OnLogExecuting = (sql, pars) => { }; }); return sqlSugar; }); services.AddControllersWithViews(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); } } }
以上是mysql批量插入BulkCopy如何實現的詳細內容。更多資訊請關注PHP中文網其他相關文章!