Hi all!
I'm writing my first serious ADO.NET app, and i don't know if i'm do correctly some stuffs. I will write a app with 3 tiers, one data base acces, other communications and other user interface. First and second will be a .dll, that i will can replace in the future.
I read that is better open and close the DB connection each time than open at application start and close before application close because .NET has something named "connections pool", it's true Can i use the same DB connection for multiple data adaptors in multiple threads
I want multithreading access and that my .dll be responsiveness, without bloking. I write a couple of delegates to permit Invoke and BeginInvoke.
I want know if this code model is correctly, scalable, and if you would change somethig.
A lot of thanks in advance.
| | using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using System.Security;
namespace BaseDeDatos { public static class Peticiones
{ public delegate void _PeticionBD (out DataSet dsResultado); public static _PeticionBD NumeroDeNombramientos = new _PeticionBD(numeroDeNombramientos); public static _PeticionBD EmpleadosRepetidos = new _PeticionBD(empleadosRepetidos); public static _PeticionBD EmpleadoOBusANULL = new _PeticionBD(empleadoOBusANULL); public static _PeticionBD AutobusesRepetidos = new _PeticionBD(autobusesRepetidos); private static SecureString sconnectionString = new SecureString(); private static bool IsReady = false; public static void Conecta(string Source, string Login, string Pass) { OracleConnectionStringBuilder builder = new OracleConnectionStringBuilder(); builder["Data Source"] = Source; builder["Integrated Security"] = false; builder.PersistSecurityInfo = false; builder["UID"] = Login; builder["pwd"] = Pass; string s = builder.ToString(); foreach (char c in s) sconnectionString.AppendChar(c); sconnectionString.MakeReadOnly(); IsReady = true; } private static void numeroDeNombramientos(out DataSet dsResultado) { if (IsReady) { OracleConnection OC = new OracleConnection(sconnectionString.ToString()); OracleDataAdapter ODA = new OracleDataAdapter("SELECT DISTINCT LIN_ID, LIN_CODIGO FROM ARTAS", OC); dsResultado = new DataSet(); try
{ OC.Open(); ODA.Fill(dsResultado); } catch (Exception Ex) { throw new DataException("Error en numeroDeNombramientos", Ex); } finally
{ OC.Close(); ODA.Dispose(); } } else throw new DataException("No se ha expecificado cadena de conexion,\nejecute metodo \'Conecta\'"); } private static void empleadosRepetidos(out DataSet dsResultado) { dsResultado = new DataSet(); } private static void empleadoOBusANULL(out DataSet dsResultado) { dsResultado = new DataSet(); } private static void autobusesRepetidos(out DataSet dsResultado) { dsResultado = new DataSet(); }
} }
|
Regards.
PD: I HATE this forums engine.
.NET Development31
|