/// <summary> /// 获取数据库连接信息 /// </summary> /// <returns>数据库连接信息</returns> public unsafe Sql.Connection Get() { ProviderAttribute provider = EnumAttribute <Provider, ProviderAttribute> .Array((byte)Provider); byte *buffer = AutoCSer.UnmanagedPool.Default.Get(); try { using (CharStream connectionStream = new CharStream((char *)buffer, AutoCSer.UnmanagedPool.DefaultSize >> 1)) { connectionStream.SimpleWriteNotNull("Provider="); connectionStream.Write(provider.Name); connectionStream.SimpleWriteNotNull(";Data Source="); connectionStream.Write(DataSource); if (Password != null) { connectionStream.WriteNotNull(";Database Password="******";Extended Properties='"); connectionStream.Write(provider.Excel); connectionStream.WriteNotNull(IsTitleColumn ? ";HDR=YES;IMEX=" : ";HDR=NO;IMEX="); AutoCSer.Extension.Number.ToString((byte)Intermixed, connectionStream); connectionStream.Write('\''); return(new Sql.Connection { Type = ClientType.Excel, ConnectionString = connectionStream.ToString() }); } } finally { AutoCSer.UnmanagedPool.Default.Push(buffer); } }
/// <summary> /// 获取数据库连接信息 /// </summary> /// <param name="isPool">是否启用数据库连接池</param> /// <returns>数据库连接信息</returns> public unsafe Sql.Connection Get(bool isPool = false) { ProviderAttribute provider = EnumAttribute <Provider, ProviderAttribute> .Array((byte)Provider); AutoCSer.Memory.Pointer buffer = UnmanagedPool.Default.GetPointer(); try { using (CharStream connectionStream = new CharStream(ref buffer)) { connectionStream.SimpleWrite("Provider="); connectionStream.Write(provider.Name); connectionStream.SimpleWrite(";Data Source="); connectionStream.Write(DataSource); if (Password != null) { connectionStream.Write(";Database Password="******";Extended Properties='"); connectionStream.Write(provider.Excel); connectionStream.Write(IsTitleColumn ? ";HDR=YES;IMEX=" : ";HDR=NO;IMEX="); AutoCSer.Extensions.NumberExtension.ToString((byte)Intermixed, connectionStream); connectionStream.Write('\''); return(new Sql.Connection { Type = ClientKind.Excel, ConnectionString = connectionStream.ToString(), IsPool = isPool }); } } finally { UnmanagedPool.Default.Push(ref buffer); } }