Here are the examples of the csharp api System.Data.IDataReader.Close() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
526 Examples
19
Source : Extension.cs
with MIT License
from AlenToma
with MIT License
from AlenToma
internal static IList DataReaderConverter(Transaction.Transaction repository, IDataReader reader, ISqlCommand command, Type type)
{
var tType = type.GetActualType();
var attachable = tType.GetPrimaryKey() != null;
var baseListType = typeof(List<>);
var listType = baseListType.MakeGenericType(tType);
var iList = DeepCloner.CreateInstance(listType) as IList;
var props = DeepCloner.GetFastDeepClonerProperties(tType);
try
{
var colNames = new SafeValueType<int, string>();
var pp = new SafeValueType<int, IFastDeepClonerProperty>();
while (reader.Read())
{
object item = null;
object replacedem = null;
item = DeepCloner.CreateInstance(tType);
replacedem = attachable ? DeepCloner.CreateInstance(tType) : null;
var col = 0;
while (col < reader.FieldCount)
{
string columnName;
if (colNames.ContainsKey(col))
columnName = colNames[col];
else
{
columnName = reader.GetName(col);
colNames.TryAdd(col, columnName);
}
var value = reader[columnName];
IFastDeepClonerProperty prop;
if (!pp.ContainsKey(col))
{
prop = DeepCloner.GetProperty(tType, columnName);
if (prop == null)
prop = props.FirstOrDefault(x => string.Equals(x.GetPropertyName(), columnName, StringComparison.CurrentCultureIgnoreCase) || x.GetPropertyName().ToLower() == columnName);
pp.TryAdd(col, prop);
}
else prop = pp[col];
if (prop != null && value != DBNull.Value && value != null && prop.CanRead)
{
if (value as byte[] != null && prop.PropertyType.FullName.Contains("Guid"))
value = new Guid(value as byte[]);
var dataEncode = prop.GetCustomAttribute<DataEncode>();
if (prop.ContainAttribute<ToBase64String>())
{
if (value.ConvertValue<string>().IsBase64String())
value = MethodHelper.DecodeStringFromBase64(value.ConvertValue<string>());
else value = MethodHelper.ConvertValue(value, prop.PropertyType);
}
else if (dataEncode != null)
value = new DataCipher(dataEncode.Key, dataEncode.KeySize).Decrypt(value.ConvertValue<string>());
else if (prop.ContainAttribute<JsonDoreplacedent>())
value = value?.ToString().FromJson(prop.PropertyType);
else if (prop.ContainAttribute<XmlDoreplacedent>())
value = value?.ToString().FromXml();
else value = MethodHelper.ConvertValue(value, prop.PropertyType);
prop.SetValue(item, value);
if (attachable)
prop.SetValue(replacedem, value);
}
col++;
}
if (replacedem != null && !(repository?.IsAttached(replacedem) ?? true))
repository?.AttachNew(replacedem);
iList.Add(item);
}
}
catch (Exception e)
{
throw new EnreplacedyException(e.Message);
}
finally
{
reader.Close();
reader.Dispose();
if (repository.OpenedDataReaders.ContainsKey(reader))
repository.OpenedDataReaders.Remove(reader);
}
return iList;
}
19
Source : Extension.cs
with MIT License
from AlenToma
with MIT License
from AlenToma
internal static ILightDataTable ReadData(this ILightDataTable data, DataBaseTypes dbType, IDataReader reader, ISqlCommand command, string primaryKey = null, bool closeReader = true)
{
var i = 0;
data.TablePrimaryKey = primaryKey;
if (reader.FieldCount <= 0)
{
if (closeReader)
{
reader.Close();
reader.Dispose();
}
return data;
}
var key = command.Command.CommandText;
try
{
if (!CachedSqlException.ContainsKey(key))
{
if (!CachedGetSchemaTable.ContainsKey(key))
CachedGetSchemaTable.Add(key, new LightDataTable(reader.GetSchemaTable()));
foreach (var item in CachedGetSchemaTable[key].Rows)
{
var columnName = item.Value<string>("ColumnName");
data.TablePrimaryKey = data.TablePrimaryKey == null && item.Columns.ContainsKey("IsKey") && item.TryValueAndConvert<bool>("IsKey", false) ? columnName : data.TablePrimaryKey;
var dataType = TypeByTypeAndDbIsNull(item["DataType"] as Type,
item.TryValueAndConvert<bool>("AllowDBNull", true));
if (data.Columns.ContainsKey(columnName))
columnName = columnName + i;
data.AddColumn(columnName, dataType);
i++;
}
}
else
{
for (var col = 0; col < reader.FieldCount; col++)
{
var columnName = reader.GetName(col);
var dataType = TypeByTypeAndDbIsNull(reader.GetFieldType(col) as Type, true);
if (data.Columns.ContainsKey(columnName))
columnName = columnName + i;
data.AddColumn(columnName, dataType);
i++;
}
}
}
catch (Exception e)
{
if (!string.IsNullOrEmpty(key))
{
CachedSqlException.Add(key, e);
return ReadData(data, dbType, reader, command, primaryKey);
}
else throw new EnreplacedyException(e.Message);
}
while (reader.Read())
{
var row = data.NewRow();
reader.GetValues(row._itemArray);
data.AddRow(row);
}
if (closeReader)
{
reader.Close();
reader.Dispose();
}
return data;
}
19
Source : DimensionHealthCheck.cs
with MIT License
from ASStoredProcedures
with MIT License
from ASStoredProcedures
private static void IDbConnectionFill(IDbConnection conn, DataSet ds, string sql)
{
IDbCommand command = conn.CreateCommand();
command.CommandText = sql;
IDataReader reader = null;
try
{
reader = command.ExecuteReader(CommandBehavior.KeyInfo);
DataTable table = new DataTable("Table");
table.Load(reader);
ds.Tables.Add(table);
}
finally
{
if ((reader != null) && !reader.IsClosed)
{
reader.Close();
}
}
}
19
Source : AdventureDb.cs
with MIT License
from blukatdevelopment
with MIT License
from blukatdevelopment
public System.Collections.Generic.Dictionary<int, ActorData> LoadActors(){
System.Collections.Generic.Dictionary<int, ActorData> actors;
actors = new System.Collections.Generic.Dictionary<int, ActorData>();
string sql = @"
SELECT * from actors;
";
cmd.CommandText = sql;
IDataReader rdr = cmd.ExecuteReader();
while(rdr.Read()){
string json = (string)rdr["data"];
ActorData dat = ActorData.FromJson(json);
actors.Add(dat.id, dat);
}
rdr.Close();
return actors;
}
19
Source : AdventureDb.cs
with MIT License
from blukatdevelopment
with MIT License
from blukatdevelopment
public System.Collections.Generic.Dictionary<int, ItemData> LoadItems(){
System.Collections.Generic.Dictionary<int, ItemData> items;
items = new System.Collections.Generic.Dictionary<int, ItemData>();
string sql = @"
SELECT * from items;
";
cmd.CommandText = sql;
IDataReader rdr = cmd.ExecuteReader();
while(rdr.Read()){
string json = (string)rdr["data"];
ItemData data = ItemData.FromJson(json);
items.Add(data.id, data);
}
rdr.Close();
return items;
}
19
Source : SettingsDb.cs
with MIT License
from blukatdevelopment
with MIT License
from blukatdevelopment
public string SelectSetting(string name){
string sql = @"
SELECT value FROM settings
WHERE name = @name
";
cmd.CommandText = sql;
cmd.Parameters.Add(new SqliteParameter ("@name", name));
IDataReader rdr = cmd.ExecuteReader();
string ret = "";
if(rdr.Read()){
ret = rdr["value"] as string;
}
rdr.Close();
return ret;
}
19
Source : SettingsDb.cs
with MIT License
from blukatdevelopment
with MIT License
from blukatdevelopment
public void PrintSettings(){
string sql = @"
SELECT * from settings;
";
cmd.CommandText = sql;
IDataReader rdr = cmd.ExecuteReader();
while(rdr.Read()){
GD.Print(rdr["name"] + ":" + rdr["value"]);
}
rdr.Close();
}
19
Source : Program.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
static void Main(string[] args) {
string path = System.Reflection.replacedembly.GetExecutingreplacedembly().Location;
path = path.Substring(0, path.LastIndexOf('\\') + 1);
// Console.WriteLine("Directory: {0}", path);
if (args.Length == 0 || args[0].ToLower() == "help") {
ShowUsage();
return;
}
try {
Database.Instance.Configure(path);
IddsConfig.Instance.ApplicationPath = path;
switch (args[0].ToLower()) {
case "islicensed":
Console.WriteLine(@"Cyberarms IDDS does not require licensing anymore. Please visit https://cyberarms.net for support options!");
break;
case "manualreport":
if(args.Length<2) {
Console.WriteLine("Please enter output filename as parameter.");
return;
}
string report = ReportGenerator.Instance.GetReport(String.Format("Manual report, {0:MM/dd/yyyy}", DateTime.Now),
String.Format("Manually created report for system {0}.{1}", System.Net.Dns.GetHostName(), System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName),""
,DateTime.Now.AddMonths(-1),DateTime.Now);
try {
StreamWriter sw = System.IO.File.CreateText(args[1]);
sw.Write(report);
sw.Close();
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
break;
case "exportcsv":
if (args.Length < 2) {
Console.WriteLine("Please enter output filename as parameter.");
return;
}
int lastSquenceNumber = 0;
if (args.Length > 2) {
if (!int.TryParse(args[2], out lastSquenceNumber)) {
Console.WriteLine("Please enter last sequence number as parameter.");
}
}
try {
StreamWriter swexport = System.IO.File.CreateText(args[1]);
System.Data.IDataReader rdr = IntrusionLog.ReadDifferential(lastSquenceNumber);
swexport.WriteLine("Sequence Number;Date and Time;Security Agent;IP Address;Status");
while(rdr.Read()) {
swexport.WriteLine("{0};{1};{2};{3};{4}", rdr[0].ToString(), rdr[1].ToString(), SecurityAgents.Instance.GetDisplayName(rdr[2].ToString()),
rdr[3].ToString(), IntrusionLog.GetStatusName(int.Parse(rdr[4].ToString())));
}
swexport.Flush();
swexport.Close();
rdr.Close();
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
break;
default:
ShowUsage();
break;
}
} catch (Exception ex) {
Console.WriteLine(ex);
}
}
19
Source : IddsAdmin.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
void logReader_Tick(object sender, EventArgs e) {
DateTime metering = DateTime.Now;
if (!IsUpdating && Database.Instance.IsConfigured) {
IsUpdating = true;
if (CurrentMenu == labelMenuSecurityLog && IntrusionLog.HasUpdates(LastLogId)) {
IDataReader rdr = IntrusionLog.ReadDifferential(LastLogId);
int maxLogId = LastLogId;
while (rdr.Read()) {
int action = int.Parse(rdr["Action"].ToString());
string agentId = Shared.Db.DbValueConverter.ToString(rdr["AgentId"]);
PanelSecurityLog.AddLogEntry(int.Parse(rdr["id"].ToString()), action,
agentId,
IntrusionLog.GetStatusIcon(action),
IntrusionLog.GetStatusClreplaced(action), DateTime.Parse(rdr["IncidentTime"].ToString()), rdr["ClientIP"].ToString(),
GetLogMessage(agentId,action));
if (Convert.ToInt32(rdr["Id"]) > maxLogId) maxLogId = Convert.ToInt32(rdr["Id"]);
}
rdr.Close();
rdr.Dispose();
if (maxLogId > LastLogId) LastLogId = maxLogId;
}
if (CurrentMenu == labelMenuCurrentLocks && Locks.HasUpdates(LastLockUpdate)) {
LastLockUpdate = DateTime.Now;
PanelCurrentLocks.Clear();
IDataReader locksReader = Locks.ReadLocks();
while (locksReader.Read()) {
DateTime lockDate;
DateTime unlockDate;
DateTime.TryParse(locksReader["LockDate"].ToString(), out lockDate);
DateTime.TryParse(locksReader["UnlockDate"].ToString(), out unlockDate);
PanelCurrentLocks.Add(int.Parse(locksReader["LockId"].ToString()), global::Cyberarms.IntrusionDetection.Admin.Properties.Resources.logIcon_softLock,
LockStatusAdapter.GetLockStatusName(int.Parse(locksReader["Status"].ToString())), locksReader["ClientIp"].ToString(),
locksReader["DisplayName"].ToString(),
lockDate, unlockDate, IntrusionDetection.Shared.Db.DbValueConverter.ToInt(locksReader["Status"]));
}
locksReader.Close();
locksReader.Dispose();
}
if (CurrentMenu == labelMenuHome) {
Dashboard.SetUnsuccessfulLogins(Locks.ReadUnsuccessfulLoginAttempts(DateTime.Now.AddDays(-30)));
foreach(SecurityAgent agent in SecurityAgents.Instance) {
agent.UpdateStatistics();
}
}
if (CurrentMenu == labelMenuHome || CurrentMenu == labelMenuCurrentLocks) {
int softLocks = Locks.ReadCurrentSoftLocks();
int hardLocks = Locks.ReadCurrentHardLocks();
PanelCurrentLocks.SetSoftLocks(softLocks);
PanelCurrentLocks.SetHardLocks(hardLocks);
Dashboard.SetHardLocks(hardLocks);
Dashboard.SetSoftLocks(softLocks);
}
if (!IsInitialized || (CurrentMenu == labelMenuHome || CurrentMenu == labelMenuSecurityLog)) {
// ??
}
}
IsInitialized = true;
IsUpdating = false;
System.Diagnostics.Debug.Print(DateTime.Now.Subtract(metering).TotalMilliseconds.ToString());
}
19
Source : IddsConfig.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
public void Load() {
if (!Database.Instance.IsConfigured) configureDatabase();
System.Data.IDataReader reader = null;
try {
reader = Database.Instance.ExecuteReader("select * from Configuration order by ConfigVersionNumber desc LIMIT 1");
if (reader.Read()) {
HardLockAttempts = Db.DbValueConverter.ToInt(reader["HardLockAttempts"]);
HardLockTimeHours = Db.DbValueConverter.ToInt(reader["HardLockTimeHours"]);
LockForever = Db.DbValueConverter.ToBool(reader["LockForever"]);
SoftLockAttempts = Db.DbValueConverter.ToInt(reader["SoftLockAttempts"]);
SoftLockTimeMinutes = Db.DbValueConverter.ToInt(reader["SoftLockTimeMinutes"]);
UseSafeNetworkList = Db.DbValueConverter.ToBool(reader["UseSafeNetworkList"]);
PluginDirectory = Db.DbValueConverter.ToString(reader["PluginDirectory"]);
SendInfoMail = Db.DbValueConverter.ToBool(reader["SendInfoMail"]);
SmtpPort = Db.DbValueConverter.ToInt(reader["SmtpPort"]);
SenderEmailAddress = Db.DbValueConverter.ToString(reader["SenderEmailAddress"]);
SmtpRequiresAuthentication = Db.DbValueConverter.ToBool(reader["SmtpRequiresAuthentication"]);
NotificationEmailAddress = Db.DbValueConverter.ToString(reader["NotificationEmailAddress"]);
SmtpServer = Db.DbValueConverter.ToString(reader["SmtpServer"]);
SmtpUsername = Db.DbValueConverter.ToString(reader["SmtpUsername"]);
SmtpPreplacedword = Db.DbValueConverter.ToString(reader["SmtpPreplacedword"]);
CyberSheriffContributor = Db.DbValueConverter.ToBool(reader["CyberSheriffContributor"]);
WebBasedMonitoring = Db.DbValueConverter.ToBool(reader["WebBasedMonitoring"]);
SmtpSslRequired = Db.DbValueConverter.ToBool(reader["SmtpSslRequired"]);
LoadSafeNetworks();
} else {
Database.Instance.ExecuteNonQuery(Db.Version_2_1.CREATE_DEFAULT_CONFIGURATION);
}
} catch (Exception ex) {
throw ex;
} finally {
if (reader != null && !reader.IsClosed) reader.Close();
}
}
19
Source : Locks.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
public static List<Lock> GetUnlockList() {
List<Lock> result = new List<Lock>();
if (Database.Instance.IsConfigured) {
string sqlString = @"select * from Locks where (UnlockDate<@p0 and (status=@p1 or status=@p2)) or status=@p3";
IDataReader rdr = Database.Instance.ExecuteReader(sqlString, DateTime.Now, Lock.LOCK_STATUS_HARDLOCK, Lock.LOCK_STATUS_SOFTLOCK, Lock.LOCK_STATUS_UNLOCK_REQUESTED);
while (rdr.Read()) {
Lock l = new Lock();
l.Id = Db.DbValueConverter.ToInt64(rdr["LockId"]);
l.IpAddress = Db.DbValueConverter.ToString(rdr["IpAddress"]);
l.LockDate = Db.DbValueConverter.ToDateTime(rdr["LockDate"]);
l.Port = Db.DbValueConverter.ToInt(rdr["Port"]);
l.Status = Db.DbValueConverter.ToInt(rdr["Status"]);
l.TriggerIncident = Db.DbValueConverter.ToInt64(rdr["TriggerIncident"]);
l.UnlockDate = Db.DbValueConverter.ToDateTime(rdr["UnlockDate"]);
result.Add(l);
}
rdr.Close();
return result;
} else {
throw new ApplicationException("Database not initialized");
}
}
19
Source : Locks.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
public static List<Lock> GetCurrentLocks() {
if (Database.Instance.IsConfigured) {
List<Lock> result = new List<Lock>();
string sqlString = @"select LockId, LockDate, UnlockDate, TriggerIncident, Status, Port, IpAddress from Locks where status in (@p0,@p1)";
IDataReader rdr = Database.Instance.ExecuteReader(sqlString, Lock.LOCK_STATUS_HARDLOCK, Lock.LOCK_STATUS_SOFTLOCK);
while (rdr.Read()) {
Lock l = new Lock();
l.Id = Db.DbValueConverter.ToInt64(rdr["LockId"]);
l.LockDate = Db.DbValueConverter.ToDateTime(rdr["LockDate"]);
l.UnlockDate = Db.DbValueConverter.ToDateTime(rdr["UnlockDate"]);
l.Status = Db.DbValueConverter.ToInt(rdr["Status"]);
l.Port = Db.DbValueConverter.ToInt(rdr["Port"]);
l.IpAddress = Db.DbValueConverter.ToString(rdr["IpAddress"]);
result.Add(l);
}
rdr.Close();
return result;
} else {
throw new ApplicationException("Database not initialized");
}
}
19
Source : ReportGenerator.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
public string GetEventsPerAgent(DateTime start, DateTime end) {
IDataReader rdr = Database.Instance.ExecuteReader(SELECT_BY_AGENT, start, end);
string currentAgent = String.Empty;
string currentLine = String.Empty;
bool hasValues = false;
StringBuilder sb = new StringBuilder();
long intrusionAttempts = 0;
long softLocks = 0;
long hardLocks = 0;
TotalIntrusionAttempts = 0;
TotalSoftLocks = 0;
TotalHardLocks = 0;
string agent = String.Empty;
while (rdr.Read()) {
int action = Db.DbValueConverter.ToInt(rdr["Action"]);
agent = Db.DbValueConverter.ToString(rdr["AgentName"]);
long incidents = Db.DbValueConverter.ToInt64(rdr["Incidents"]);
if(!agent.Equals(currentAgent) && hasValues) {
sb.AppendLine(SetEventsPerAgent(currentAgent, intrusionAttempts, softLocks, hardLocks));
currentAgent = agent;
intrusionAttempts = 0;
softLocks = 0;
hardLocks = 0;
} else if (!hasValues) {
currentAgent = agent;
}
switch (action) {
case IntrusionLog.STATUS_INTRUSION_ATTEMPT:
intrusionAttempts = incidents;
break;
case IntrusionLog.STATUS_SOFT_LOCKED:
softLocks = incidents;
break;
case IntrusionLog.STATUS_HARD_LOCKED:
hardLocks = incidents;
break;
}
hasValues = true;
}
if (hasValues) {
sb.AppendLine(SetEventsPerAgent(agent, intrusionAttempts, softLocks, hardLocks));
}
rdr.Close();
return sb.ToString();
}
19
Source : SecurityAgents.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
public void InitializeAgents() {
this.Clear();
if (!Database.Instance.IsConfigured) {
throw new ApplicationException("Database is not configured yet. Please configure database and re-try this operation!");
}
IDataReader rdr = Database.Instance.ExecuteReader("select * from securityAgents");
// load all agents
while (rdr.Read()) {
SecurityAgent agent = new SecurityAgent();
agent.Name = Db.DbValueConverter.ToString(rdr["Name"]);
agent.replacedemblyName = Db.DbValueConverter.ToString(rdr["replacedemblyName"]);
agent.Id = Db.DbValueConverter.ToGuid(rdr["AgentId"]);
agent.HardLockAttempts = Db.DbValueConverter.ToInt(rdr["HardLockAttempts"]);
agent.HardLockTimeHours = Db.DbValueConverter.ToInt(rdr["HardLockTimeHours"]);
agent.LockForever = Db.DbValueConverter.ToBool(rdr["LockForever"]);
agent.SoftLockAttempts = Db.DbValueConverter.ToInt(rdr["SoftLockAttempts"]);
agent.SoftLockTimeMinutes = Db.DbValueConverter.ToInt(rdr["SoftLockTimeMinutes"]);
agent.OverrideConfig = Db.DbValueConverter.ToBool(rdr["OverwriteConfiguration"]);
agent.DisplayName = Db.DbValueConverter.ToString(rdr["DisplayName"]);
agent.Enabled = Db.DbValueConverter.ToBool(rdr["Enabled"]);
agent.Serial = Db.DbValueConverter.ToInt(rdr["Serial"]);
//agent.LoadCustomConfig();
this.Add(agent);
}
rdr.Close();
}
19
Source : Locks.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
public static Lock GetLockById(long id) {
if (Database.Instance.IsConfigured) {
Lock result = new Lock();
string sqlString = @"select LockId, LockDate, UnlockDate, TriggerIncident, Status, Port, IpAddress from Locks where LockId = @p0";
IDataReader rdr = Database.Instance.ExecuteReader(sqlString, id);
if (rdr.Read()) {
result.Id = Db.DbValueConverter.ToInt64(rdr["LockId"]);
result.LockDate = Db.DbValueConverter.ToDateTime(rdr["LockDate"]);
result.UnlockDate = Db.DbValueConverter.ToDateTime(rdr["UnlockDate"]);
result.Status = Db.DbValueConverter.ToInt(rdr["Status"]);
result.Port = Db.DbValueConverter.ToInt(rdr["Port"]);
result.IpAddress = Db.DbValueConverter.ToString(rdr["IpAddress"]);
result.TriggerIncident = Db.DbValueConverter.ToInt64(rdr["TriggerIncident"]);
}
rdr.Close();
return result;
} else {
throw new ApplicationException("Database not initialized");
}
}
19
Source : SecurityAgent.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
public void Reload() {
if (!Database.Instance.IsConfigured) {
throw new ApplicationException("Database is not configured yet. Please configure database and re-try this operation!");
}
if (Id == null || Id.Equals(Guid.Empty)) return;
IDataReader rdr = Database.Instance.ExecuteReader("select * from securityAgents where AgentId=@p0", Id);
// load all agents
if (rdr.Read()) {
Name = Db.DbValueConverter.ToString(rdr["Name"]);
replacedemblyName = Db.DbValueConverter.ToString(rdr["replacedemblyName"]);
Id = Db.DbValueConverter.ToGuid(rdr["AgentId"]);
HardLockAttempts = Db.DbValueConverter.ToInt(rdr["HardLockAttempts"]);
HardLockTimeHours = Db.DbValueConverter.ToInt(rdr["HardLockTimeHours"]);
LockForever = Db.DbValueConverter.ToBool(rdr["LockForever"]);
SoftLockAttempts = Db.DbValueConverter.ToInt(rdr["SoftLockAttempts"]);
SoftLockTimeMinutes = Db.DbValueConverter.ToInt(rdr["SoftLockTimeMinutes"]);
OverrideConfig = Db.DbValueConverter.ToBool(rdr["OverwriteConfiguration"]);
DisplayName = Db.DbValueConverter.ToString(rdr["DisplayName"]);
Enabled = Db.DbValueConverter.ToBool(rdr["Enabled"]);
Serial = Db.DbValueConverter.ToInt(rdr["Serial"]);
}
rdr.Close();
LoadCustomConfig();
}
19
Source : SecurityAgent.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
public void UpdateStatistics() {
string sqlString = "select FailedLogins, HardLocks, SoftLocks from AgentStatistics where AgentId=@p0";
int hardLocks, failedLogins, softLocks;
try {
IDataReader rdr = Database.Instance.ExecuteReader(sqlString, Id);
if (rdr.Read()) {
hardLocks = Db.DbValueConverter.ToInt(rdr["HardLocks"]);
failedLogins = Db.DbValueConverter.ToInt(rdr["FailedLogins"]);
softLocks = Db.DbValueConverter.ToInt(rdr["SoftLocks"]);
if (hardLocks != HardLocks || softLocks != SoftLocks || failedLogins != FailedLogins) {
HardLocks = hardLocks;
SoftLocks = softLocks;
FailedLogins = failedLogins;
OnStatisticsUpdated();
}
} else {
HardLocks = 0;
FailedLogins = 0;
SoftLocks = 0;
}
rdr.Close();
} catch { }
}
19
Source : IddsConfig.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
private Dictionary<string, string> LoadConfig(string configTable) {
if (!Database.Instance.IsConfigured) configureDatabase();
Dictionary<string, string> config = new Dictionary<string, string>();
System.Data.IDataReader rdr = Database.Instance.ExecuteReader(String.Format("select ConfigKey, ConfigValue from {0}", configTable));
while (rdr.Read()) {
config.Add(Db.DbValueConverter.ToString(rdr["ConfigKey"]), Db.DbValueConverter.ToString(rdr["ConfigValue"]));
}
rdr.Close();
return config;
}
19
Source : IddsConfig.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
public CSafeNetworks LoadNetworkList(string list) {
if (!Database.Instance.IsConfigured) configureDatabase();
CSafeNetworks net = new CSafeNetworks();
IDataReader rdr = Database.Instance.ExecuteReader(String.Format("Select IpAddress, NetworkMask from {0}", list));
while (rdr.Read()) {
net.Add(new CSafeNetwork(Db.DbValueConverter.ToString(rdr["IpAddress"]), Db.DbValueConverter.ToString(rdr["NetworkMask"])));
}
rdr.Close();
return net;
}
19
Source : SecurityAgent.cs
with MIT License
from EFTEC
with MIT License
from EFTEC
public void LoadCustomConfig() {
IDataReader rdr = Database.Instance.ExecuteReader("select PropertyName,PropertyValueString from SecurityAgentConfig where AgentId like @p0", Id);
while (rdr.Read()) {
string propName = Db.DbValueConverter.ToString(rdr["PropertyName"]);
if (CustomConfiguration.ContainsKey(propName)) {
CustomConfiguration[propName] = Db.DbValueConverter.ToString(rdr["PropertyValueString"]);
}
}
rdr.Close();
}
19
Source : EpiDataReader.cs
with Apache License 2.0
from Epi-Info
with Apache License 2.0
from Epi-Info
void System.Data.IDataReader.Close()
{
this.mReader.Close();
}
19
Source : Project.cs
with Apache License 2.0
from Epi-Info
with Apache License 2.0
from Epi-Info
public void LoadViews()
{
this.views = new Collection<View>();
System.Collections.Hashtable RelatedViews = new System.Collections.Hashtable();
DataTable viewsTable = GetViewsAsDataTable();
foreach (DataRow viewRow in viewsTable.Rows)
{
View V = new Epi2000.View(viewRow, this);
// set the is related view attribute
IDataReader R = this.collectedData.GetTableDataReader(V.Name);
while(R.Read())
{
if (R["Name"].ToString().ToUpperInvariant().StartsWith("RELVIEW"))
{
if(! RelatedViews.ContainsKey(R["DataTable"].ToString()))
{
RelatedViews.Add(R["DataTable"].ToString(), R["DataTable"].ToString());
}
}
}
R.Close();
this.views.Add(V);
}
foreach(Epi2000.View V in this.views)
{
if (RelatedViews.ContainsKey(V.Name))
{
V.IsRelatedView = true;
}
}
}
19
Source : InternalDataReader.cs
with GNU Lesser General Public License v3.0
from faib920
with GNU Lesser General Public License v3.0
from faib920
public void Close()
{
_reader.Close();
}
19
Source : InternalDataReader.cs
with GNU Lesser General Public License v3.0
from faib920
with GNU Lesser General Public License v3.0
from faib920
protected override bool Dispose(bool disposing)
{
if (disposing)
{
_reader.Close();
_reader.Dispose();
_command.Dispose();
}
return true;
}
19
Source : DbExecuteQuery.cs
with GNU General Public License v3.0
from fiado07
with GNU General Public License v3.0
from fiado07
public bool any(SqlAndParameters sqlParameter)
{
bool result = false;
IDataReader readerResult = null;
try
{
isConnectionStringValid();
using (var sqlComand = DbConnection.DbConnectionBase.CreateCommand())
{
if (DbConnection?.DbTransaction != null)
sqlComand.Transaction = DbConnection.DbTransaction;
if (sqlComand.Parameters != null)
sqlComand.SetParameters(sqlParameter);
// set sql
sqlComand.CommandText = sqlParameter.Sql;
// set command type
sqlComand.CommandType = sqlParameter.isStoredProcedure ? CommandType.StoredProcedure : CommandType.Text;
// get and set values
readerResult = sqlComand.ExecuteReader();
while (readerResult.Read())
{
if (readerResult[0] != null) result = true;
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (readerResult != null && !readerResult.IsClosed) readerResult.Close();
if (DbConnection.canClose) DbConnection.DbConnectionBase.Close();
}
return result;
}
19
Source : DbExecuteQuery.cs
with GNU General Public License v3.0
from fiado07
with GNU General Public License v3.0
from fiado07
public T ExecuteSqlGetObject<T>(SqlAndParameters sqlParameter) where T : new()
{
T objectType = new T();
IDataReader readerResult = null;
try
{
isConnectionStringValid();
using (var sqlComand = DbConnection.DbConnectionBase.CreateCommand())
{
if (DbConnection?.DbTransaction != null)
sqlComand.Transaction = DbConnection.DbTransaction;
if (sqlComand?.Parameters != null)
sqlComand.SetParameters(sqlParameter);
// set sql
sqlComand.CommandText = sqlParameter.Sql;
// set command type
sqlComand.CommandType = sqlParameter.isStoredProcedure ? CommandType.StoredProcedure : CommandType.Text;
// get and set values
readerResult = sqlComand.ExecuteReader(CommandBehavior.SingleRow);
// map data from reader to new object
objectType = Mappers.Mapper.Map<T>(readerResult).FirstOrDefault();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (readerResult != null && !readerResult.IsClosed) readerResult.Close();
if (DbConnection.canClose) DbConnection.DbConnectionBase.Close();
}
return objectType;
}
19
Source : DataAdapter.cs
with MIT License
from GrapeCity
with MIT License
from GrapeCity
internal int FillInternal (DataTable dataTable, IDataReader dataReader)
{
if (dataReader.FieldCount == 0) {
dataReader.Close ();
return 0;
}
int count = 0;
try {
string tableName = SetupSchema (SchemaType.Mapped, dataTable.TableName);
if (tableName != null) {
dataTable.TableName = tableName;
FillTable (dataTable, dataReader, 0, 0, ref count);
}
} finally {
dataReader.Close ();
}
return count;
}
19
Source : DataAdapter.cs
with MIT License
from GrapeCity
with MIT License
from GrapeCity
internal int FillInternal (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords)
{
if (dataSet == null)
throw new ArgumentNullException ("DataSet");
if (startRecord < 0)
throw new ArgumentException ("The startRecord parameter was less than 0.");
if (maxRecords < 0)
throw new ArgumentException ("The maxRecords parameter was less than 0.");
DataTable dataTable = null;
int resultIndex = 0;
int count = 0;
try {
string tableName = srcTable;
do {
// Non-resultset queries like insert, delete or update aren't processed.
if (dataReader.FieldCount != -1) {
tableName = SetupSchema (SchemaType.Mapped, tableName);
if (tableName != null) {
// check if the table exists in the dataset
if (dataSet.Tables.Contains (tableName))
// get the table from the dataset
dataTable = dataSet.Tables [tableName];
else {
// Do not create schema if MissingSchemAction is set to Ignore
if (this.MissingSchemaAction == MissingSchemaAction.Ignore)
continue;
dataTable = dataSet.Tables.Add (tableName);
}
if (!FillTable (dataTable, dataReader, startRecord, maxRecords, ref count))
continue;
tableName = String.Format ("{0}{1}", srcTable, ++resultIndex);
startRecord = 0;
maxRecords = 0;
}
}
} while (dataReader.NextResult ());
} finally {
dataReader.Close ();
}
return count;
}
19
Source : DbDataAdapter.cs
with MIT License
from GrapeCity
with MIT License
from GrapeCity
protected virtual DataTable FillSchema (DataTable dataTable, SchemaType schemaType, IDbCommand command, CommandBehavior behavior)
{
if (dataTable == null)
throw new ArgumentNullException ("DataTable");
behavior |= CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo;
if (command.Connection.State == ConnectionState.Closed) {
command.Connection.Open ();
behavior |= CommandBehavior.CloseConnection;
}
IDataReader reader = command.ExecuteReader (behavior);
try
{
string tableName = SetupSchema (schemaType, dataTable.TableName);
if (tableName != null)
{
// FillSchema should add the KeyInfo unless MissingSchemaAction
// is set to Ignore or Error.
MissingSchemaAction schemaAction = MissingSchemaAction;
if (!(schemaAction == MissingSchemaAction.Ignore ||
schemaAction == MissingSchemaAction.Error))
schemaAction = MissingSchemaAction.AddWithKey;
BuildSchema (reader, dataTable, schemaType, schemaAction,
MissingMappingAction, TableMappings);
}
}
finally
{
reader.Close ();
}
return dataTable;
}
19
Source : DbDataAdapter.cs
with MIT License
from GrapeCity
with MIT License
from GrapeCity
protected virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType, IDbCommand command, string srcTable, CommandBehavior behavior)
{
if (dataSet == null)
throw new ArgumentNullException ("DataSet");
behavior |= CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo;
if (command.Connection.State == ConnectionState.Closed) {
command.Connection.Open ();
behavior |= CommandBehavior.CloseConnection;
}
IDataReader reader = command.ExecuteReader (behavior);
ArrayList output = new ArrayList ();
string tableName = srcTable;
int index = 0;
DataTable table;
try
{
// FillSchema should add the KeyInfo unless MissingSchemaAction
// is set to Ignore or Error.
MissingSchemaAction schemaAction = MissingSchemaAction;
if (!(MissingSchemaAction == MissingSchemaAction.Ignore ||
MissingSchemaAction == MissingSchemaAction.Error))
schemaAction = MissingSchemaAction.AddWithKey;
do {
tableName = SetupSchema (schemaType, tableName);
if (tableName != null)
{
if (dataSet.Tables.Contains (tableName))
table = dataSet.Tables [tableName];
else
{
// Do not create schema if MissingSchemAction is set to Ignore
if (this.MissingSchemaAction == MissingSchemaAction.Ignore)
continue;
table = dataSet.Tables.Add (tableName);
}
BuildSchema (reader, table, schemaType, schemaAction,
MissingMappingAction, TableMappings);
output.Add (table);
tableName = String.Format ("{0}{1}", srcTable, ++index);
}
}while (reader.NextResult ());
}
finally
{
reader.Close ();
}
return (DataTable[]) output.ToArray (typeof (DataTable));
}
19
Source : DbDataAdapter.cs
with MIT License
from GrapeCity
with MIT License
from GrapeCity
protected virtual int Update (DataRow[] dataRows, DataTableMapping tableMapping)
{
int updateCount = 0;
foreach (DataRow row in dataRows) {
StatementType statementType = StatementType.Update;
IDbCommand command = null;
string commandName = String.Empty;
switch (row.RowState) {
case DataRowState.Added:
statementType = StatementType.Insert;
command = ((IDbDataAdapter) this).InsertCommand;
commandName = "Insert";
break;
case DataRowState.Deleted:
statementType = StatementType.Delete;
command = ((IDbDataAdapter) this).DeleteCommand;
commandName = "Delete";
break;
case DataRowState.Modified:
statementType = StatementType.Update;
command = ((IDbDataAdapter) this).UpdateCommand;
commandName = "Update";
break;
case DataRowState.Unchanged:
case DataRowState.Detached:
continue;
}
RowUpdatingEventArgs argsUpdating = CreateRowUpdatingEvent (row, command, statementType, tableMapping);
row.RowError = null;
OnRowUpdating (argsUpdating);
switch (argsUpdating.Status) {
case UpdateStatus.Continue :
//continue in update operation
break;
case UpdateStatus.ErrorsOccurred :
if (argsUpdating.Errors == null) {
argsUpdating.Errors = ExceptionHelper.RowUpdatedError();
}
row.RowError += argsUpdating.Errors.Message;
if (!ContinueUpdateOnError) {
throw argsUpdating.Errors;
}
continue;
case UpdateStatus.SkipAllRemainingRows :
return updateCount;
case UpdateStatus.SkipCurrentRow :
updateCount++;
continue;
default :
throw ExceptionHelper.InvalidUpdateStatus (argsUpdating.Status);
}
command = argsUpdating.Command;
try {
if (command != null) {
DataColumnMappingCollection columnMappings = tableMapping.ColumnMappings;
IDataParameter nullCheckParam = null;
foreach (IDataParameter parameter in command.Parameters) {
if ((parameter.Direction & ParameterDirection.Input) != 0) {
string dsColumnName = parameter.SourceColumn;
if (columnMappings.Contains(parameter.SourceColumn))
dsColumnName = columnMappings [parameter.SourceColumn].DataSetColumn;
if (dsColumnName == null || dsColumnName.Length <= 0) {
nullCheckParam = parameter;
continue;
}
DataRowVersion rowVersion = parameter.SourceVersion;
// Parameter version is ignored for non-update commands
if (statementType == StatementType.Delete)
rowVersion = DataRowVersion.Original;
parameter.Value = row [dsColumnName, rowVersion];
if (nullCheckParam != null && (parameter.Value != null
&& parameter.Value != DBNull.Value)) {
nullCheckParam.Value = 0;
nullCheckParam = null;
}
}
}
}
}
catch (Exception e) {
argsUpdating.Errors = e;
argsUpdating.Status = UpdateStatus.ErrorsOccurred;
}
IDataReader reader = null;
try {
if (command == null) {
throw ExceptionHelper.UpdateRequiresCommand (commandName);
}
CommandBehavior commandBehavior = CommandBehavior.Default;
if (command.Connection.State == ConnectionState.Closed) {
command.Connection.Open ();
commandBehavior |= CommandBehavior.CloseConnection;
}
// use ExecuteReader because we want to use the commandbehavior parameter.
// so the connection will be closed if needed.
reader = command.ExecuteReader (commandBehavior);
// update the current row, if the update command returns any resultset
// ignore other than the first record.
DataColumnMappingCollection columnMappings = tableMapping.ColumnMappings;
if (command.UpdatedRowSource == UpdateRowSource.Both ||
command.UpdatedRowSource == UpdateRowSource.FirstReturnedRecord) {
if (reader.Read ()){
DataTable retSchema = reader.GetSchemaTable ();
foreach (DataRow dr in retSchema.Rows) {
string columnName = dr ["ColumnName"].ToString ();
string dstColumnName = columnName;
if (columnMappings != null &&
columnMappings.Contains(columnName))
dstColumnName = columnMappings [dstColumnName].DataSetColumn;
DataColumn dstColumn = row.Table.Columns [dstColumnName];
if (dstColumn == null
#if NOT_PFX
|| (dstColumn.Expression != null
&& dstColumn.Expression.Length > 0)
#endif
)
continue;
// info from : http://www.error-bank.com/microsoft.public.dotnet.framework.windowsforms.databinding/
// [email protected]_Thread.aspx
// disable readonly for non-expression columns.
bool readOnlyState = dstColumn.ReadOnly;
dstColumn.ReadOnly = false;
try {
row [dstColumnName] = reader [columnName];
} finally {
dstColumn.ReadOnly = readOnlyState;
}
}
}
}
reader.Close ();
int tmp = reader.RecordsAffected; // records affected is valid only after closing reader
// if the execute does not effect any rows we throw an exception.
if (tmp == 0)
throw new DBConcurrencyException("Concurrency violation: the " +
commandName +"Command affected 0 records.");
updateCount += tmp;
if (command.UpdatedRowSource == UpdateRowSource.Both ||
command.UpdatedRowSource == UpdateRowSource.OutputParameters) {
// Update output parameters to row values
foreach (IDataParameter parameter in command.Parameters) {
if (parameter.Direction != ParameterDirection.InputOutput
&& parameter.Direction != ParameterDirection.Output
&& parameter.Direction != ParameterDirection.ReturnValue)
continue;
string dsColumnName = parameter.SourceColumn;
if (columnMappings != null &&
columnMappings.Contains(parameter.SourceColumn))
dsColumnName = columnMappings [parameter.SourceColumn].DataSetColumn;
DataColumn dstColumn = row.Table.Columns [dsColumnName];
if (dstColumn == null
#if NOT_PFX
|| (dstColumn.Expression != null
&& dstColumn.Expression.Length > 0)
#endif
)
continue;
bool readOnlyState = dstColumn.ReadOnly;
dstColumn.ReadOnly = false;
try {
row [dsColumnName] = parameter.Value;
} finally {
dstColumn.ReadOnly = readOnlyState;
}
}
}
RowUpdatedEventArgs updatedArgs = CreateRowUpdatedEvent (row, command, statementType, tableMapping);
OnRowUpdated (updatedArgs);
switch (updatedArgs.Status) {
case UpdateStatus.Continue:
break;
case UpdateStatus.ErrorsOccurred:
if (updatedArgs.Errors == null) {
updatedArgs.Errors = ExceptionHelper.RowUpdatedError();
}
row.RowError += updatedArgs.Errors.Message;
if (!ContinueUpdateOnError) {
throw updatedArgs.Errors;
}
break;
case UpdateStatus.SkipCurrentRow:
continue;
case UpdateStatus.SkipAllRemainingRows:
return updateCount;
}
#if NET_2_0
if (!AcceptChangesDuringUpdate)
continue;
#endif
row.AcceptChanges ();
} catch(Exception e) {
row.RowError = e.Message;
if (!ContinueUpdateOnError) {
throw e;
}
} finally {
if (reader != null && ! reader.IsClosed) {
reader.Close ();
}
}
}
return updateCount;
}
19
Source : DbEnumerator.cs
with MIT License
from GrapeCity
with MIT License
from GrapeCity
public bool MoveNext ()
{
if (reader.Read ())
return true;
if (closeReader)
reader.Close ();
return false;
}
19
Source : MySQLEstateData.cs
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
private EstateSettings LoadEstateSettingsOnly(uint estateID)
{
EstateSettings es = new EstateSettings();
es.OnSave += StoreEstateSettings;
string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + " from estate_settings where estate_settings.EstateID = ?EstateID";
using (MySqlConnection conn = GetConnection())
{
using (MySqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("?EstateID", estateID.ToString());
IDataReader r = cmd.ExecuteReader();
if (!r.Read())
{
r.Close();
return null;
}
foreach (string name in FieldList)
{
if (m_FieldMap[name].GetValue(es) is bool)
{
int v = Convert.ToInt32(r[name]);
if (v != 0)
m_FieldMap[name].SetValue(es, true);
else
m_FieldMap[name].SetValue(es, false);
}
else if (m_FieldMap[name].GetValue(es) is UUID)
{
UUID uuid = UUID.Zero;
UUID.TryParse(r[name].ToString(), out uuid);
m_FieldMap[name].SetValue(es, uuid);
}
else
{
m_FieldMap[name].SetValue(es, r[name]);
}
}
r.Close();
return es;
}
}
}
19
Source : MySQLEstateData.cs
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
private EstateSettings NewEstateSettings(uint estateID, string regionName, UUID masterAvatarID)
{
// 0 will be treated as "create estate settings with a new ID"
EstateSettings es = new EstateSettings();
es.OnSave += StoreEstateSettings;
List<string> names = new List<string>(FieldList);
using (MySqlConnection conn = GetConnection())
{
es.EstateName = regionName;
if (estateID == 0)
{
names.Remove("EstateID"); // generate one
}
else
{
es.EstateID = estateID; // use this one
es.ParentEstateID = estateID; // default is same
}
// The EstateOwner is not filled in yet. It needs to be.
es.EstateOwner = masterAvatarID;
string sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")";
using (MySqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.Clear();
foreach (string name in FieldList)
{
if (m_FieldMap[name].GetValue(es) is bool)
{
if ((bool)m_FieldMap[name].GetValue(es))
cmd.Parameters.AddWithValue("?" + name, "1");
else
cmd.Parameters.AddWithValue("?" + name, "0");
}
else
{
cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
}
}
cmd.ExecuteNonQuery();
// If we generated a new estate ID, fetch it
if (estateID == 0)
{
// Now fetch the auto-generated estate ID.
cmd.CommandText = "select LAST_INSERT_ID() as id";
cmd.Parameters.Clear();
IDataReader r = cmd.ExecuteReader();
r.Read();
es.EstateID = Convert.ToUInt32(r["id"]);
r.Close();
// If we auto-generated the Estate ID, then ParentEstateID is still the default (100). Fix it to default to the same value.
es.ParentEstateID = es.EstateID;
cmd.CommandText = "UPDATE estate_settings SET ParentEstateID=?ParentEstateID WHERE EstateID=?EstateID";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("ParentEstateID", es.ParentEstateID.ToString());
cmd.Parameters.AddWithValue("EstateID", es.EstateID.ToString());
cmd.ExecuteNonQuery();
}
return es;
}
}
}
19
Source : MySQLEstateData.cs
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
private bool GetEstateMap(UUID regionID, out uint estateID)
{
bool result = false;
estateID = 0;
string sql = "select * from estate_map where RegionID = ?RegionID";
using (MySqlConnection conn = GetConnection())
{
using (MySqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
IDataReader r = cmd.ExecuteReader();
if (r.Read())
{
if (uint.TryParse(r["EstateID"].ToString(), out estateID))
result = true;
}
r.Close();
return result;
}
}
}
19
Source : MySQLEstateData.cs
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
private void LoadBanList(EstateSettings es)
{
es.ClearBans();
using (MySqlConnection conn = GetConnection())
{
using (MySqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select bannedUUID from estateban where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", es.EstateID);
IDataReader r = cmd.ExecuteReader();
while (r.Read())
{
EstateBan eb = new EstateBan();
UUID uuid = new UUID();
UUID.TryParse(r["bannedUUID"].ToString(), out uuid);
eb.BannedUserID = uuid;
eb.BannedHostAddress = "0.0.0.0";
eb.BannedHostIPMask = "0.0.0.0";
es.AddBan(eb);
}
r.Close();
}
}
}
19
Source : MySQLEstateData.cs
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
UUID[] LoadUUIDList(uint EstateID, string table)
{
List<UUID> uuids = new List<UUID>();
using (MySqlConnection conn = GetConnection())
{
using (MySqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select uuid from " + table + " where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", EstateID);
IDataReader r = cmd.ExecuteReader();
while (r.Read())
{
// EstateBan eb = new EstateBan();
UUID uuid = new UUID();
UUID.TryParse(r["uuid"].ToString(), out uuid);
uuids.Add(uuid);
}
r.Close();
return uuids.ToArray();
}
}
}
19
Source : MySQLEstateData.cs
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
public List<UUID> GetEstateRegions(uint estateID)
{
using (MySqlConnection conn = GetConnection())
{
using (MySqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select RegionID from estate_map where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", estateID);
IDataReader r = cmd.ExecuteReader();
List<UUID> regions = new List<UUID>();
while (r.Read())
{
EstateBan eb = new EstateBan();
UUID uuid = new UUID();
UUID.TryParse(r["RegionID"].ToString(), out uuid);
regions.Add(uuid);
}
r.Close();
return regions;
}
}
}
19
Source : MySQLSimpleDB.cs
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
with BSD 3-Clause "New" or "Revised" License
from HalcyonGrid
private List<Dictionary<string, string>> ReaderToResultSet(IDataReader r)
{
List<Dictionary<string, string>> resultSet = new List<Dictionary<string, string>>();
using (r)
{
while (r.Read())
{
Dictionary<string, string> row = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
for (int i = 0; i < r.FieldCount; i++)
{
if (!r.IsDBNull(i)) row[r.GetName(i)] = r.GetString(i);
else row[r.GetName(i)] = null;
}
resultSet.Add(row);
}
r.Close();
}
return resultSet;
}
19
Source : OracleExecuteReaderFixture.cs
with MIT License
from iccb1013
with MIT License
from iccb1013
[TestMethod]
public void Bug869Test()
{
object[] paramarray = new object[2];
paramarray[0] = "BLAUS";
paramarray[1] = null;
using (IDataReader dataReader = db.ExecuteReader("GetCustomersTest", paramarray))
{
while (dataReader.Read())
{
replacedert.IsNotNull(dataReader["ContactName"]);
}
dataReader.Close();
}
}
19
Source : OracleExecuteReaderFixture.cs
with MIT License
from iccb1013
with MIT License
from iccb1013
[TestMethod]
public void CanGetTheInnerDataReader()
{
DbCommand queryCommand = db.GetSqlStringCommand(queryString);
IDataReader reader = db.ExecuteReader(queryCommand);
string acreplacedulator = "";
int descriptionIndex = reader.GetOrdinal("RegionDescription");
OracleDataReader innerReader = ((OracleDataReaderWrapper)reader).InnerReader;
replacedert.IsNotNull(innerReader);
while (reader.Read())
{
acreplacedulator += innerReader.GetOracleString(descriptionIndex).Value.Trim();
}
reader.Close();
replacedert.AreEqual("EasternWesternNorthernSouthern", acreplacedulator);
replacedert.AreEqual(ConnectionState.Closed, queryCommand.Connection.State);
}
19
Source : ExecuteReaderFixture.cs
with MIT License
from iccb1013
with MIT License
from iccb1013
public void CanExecuteQueryThroughDataReaderUsingTransaction()
{
using (DbConnection connection = db.CreateConnection())
{
connection.Open();
using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
{
using (IDataReader reader = db.ExecuteReader(insertCommand, transaction.Transaction))
{
replacedert.AreEqual(1, reader.RecordsAffected);
reader.Close();
}
}
replacedert.AreEqual(ConnectionState.Open, connection.State);
}
}
19
Source : ExecuteReaderFixture.cs
with MIT License
from iccb1013
with MIT License
from iccb1013
public void CanExecuteReaderFromDbCommand()
{
IDataReader reader = db.ExecuteReader(queryCommand);
string acreplacedulator = "";
while (reader.Read())
{
acreplacedulator += ((string)reader["RegionDescription"]).Trim();
}
reader.Close();
replacedert.AreEqual("EasternWesternNorthernSouthern", acreplacedulator);
replacedert.AreEqual(ConnectionState.Closed, queryCommand.Connection.State);
}
19
Source : ExecuteReaderFixture.cs
with MIT License
from iccb1013
with MIT License
from iccb1013
public void CanExecuteReaderWithCommandText()
{
IDataReader reader = db.ExecuteReader(CommandType.Text, queryString);
string acreplacedulator = "";
while (reader.Read())
{
acreplacedulator += ((string)reader["RegionDescription"]).Trim();
}
reader.Close();
replacedert.AreEqual("EasternWesternNorthernSouthern", acreplacedulator);
}
19
Source : ExecuteReaderFixture.cs
with MIT License
from iccb1013
with MIT License
from iccb1013
public void WhatGetsReturnedWhenWeDoAnInsertThroughDbCommandExecute()
{
int count = -1;
IDataReader reader = null;
try
{
reader = db.ExecuteReader(insertCommand);
count = reader.RecordsAffected;
}
finally
{
if (reader != null)
{
reader.Close();
}
string deleteString = "Delete from Region where RegionId = 99";
DbCommand cleanupCommand = db.GetSqlStringCommand(deleteString);
db.ExecuteNonQuery(cleanupCommand);
}
replacedert.AreEqual(1, count);
}
19
Source : InternalDataReader.cs
with MIT License
from JackQChen
with MIT License
from JackQChen
public void Close()
{
if (!this._reader.IsClosed)
{
try
{
this._reader.Close();
this._reader.Dispose();/* Tips:.NET Core 的 SqlServer 驱动 System.Data.SqlClient(4.1.0) 中,调用 DataReader.Dispose() 方法后才能拿到 Output 参数值。为了与 ChloeCore 版本的代码统一,也在这执行 DataReader.Dispose() 吧 */
OutputParameter.CallMapValue(this._outputParameters);
}
finally
{
this._adoSession.Complete();
}
}
}
19
Source : InternalSqlQuery.cs
with MIT License
from JackQChen
with MIT License
from JackQChen
public bool MoveNext()
{
if (this._hasFinished || this._disposed)
return false;
if (this._reader == null)
{
this.Prepare();
}
if (this._reader.Read())
{
this._current = (T)this._objectActivator.CreateInstance(this._reader);
return true;
}
else
{
this._reader.Close();
this._current = default(T);
this._hasFinished = true;
return false;
}
}
19
Source : QueryEnumerator.cs
with MIT License
from JackQChen
with MIT License
from JackQChen
public bool MoveNext()
{
if (this._hasFinished || this._disposed)
return false;
if (this._reader == null)
{
//TODO 执行 sql 语句,获取 DataReader
this._reader = this._adoSession.ExecuteReader(this._commandFactor.CommandText, this._commandFactor.Parameters, CommandType.Text);
}
if (this._reader.Read())
{
this._current = (T)this._objectActivator.CreateInstance(this._reader);
return true;
}
else
{
this._reader.Close();
this._current = default(T);
this._hasFinished = true;
return false;
}
}
19
Source : InternalSqlQuery.cs
with MIT License
from JackQChen
with MIT License
from JackQChen
public void Dispose()
{
if (this._disposed)
return;
if (this._reader != null)
{
if (!this._reader.IsClosed)
this._reader.Close();
this._reader.Dispose();
this._reader = null;
}
if (!this._hasFinished)
{
this._hasFinished = true;
}
this._current = default(T);
this._disposed = true;
}
19
Source : ChloeMySqlDataReader.cs
with MIT License
from JackQChen
with MIT License
from JackQChen
public void Close()
{
this._reader.Close();
}
See More Examples