Scrigroup - Documente si articole

     

HomeDocumenteUploadResurseAlte limbi doc
AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows
WordXml

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

The DBConnectionSingleton Class

c



+ Font mai mare | - Font mai mic



The DBConnectionSingleton Class

The DBConnectionSingleton class is the implementation of a database connection-specific object pool. The main purpose of this class is to provide database connection-specific implementations of the Create(), Validate(), and Expire() methods inherited from the ObjectPool class. The class also provides methods called BorrowDBConnection() and ReturnDBConnection() for borrowing and returning database connection objects from the object pool.



The complete listing of the DBConnectionSingleton class is as follows:

using System;
using System.Data.SqlClient;

namespace WroxCS


public static readonly DBConnectionSingleton Instance =
new DBConnectionSingleton();

private static string _connectionString =
@'server=(local);Trusted Connection=yes;database=northwind';

public static string ConnectionString

get



protected override object Create()


protected override bool Validate(object o)

catch (SqlException)



protected override void Expire(object o)

catch (SqlException)



public SqlConnection BorrowDBConnection()

catch (Exception e)


public void ReturnDBConnection(SqlConnection c)



As you are dealing with the SqlConnection object, the Expire() method closes the SqlConnection, the Create() method creates the SqlConnection, and the Validate() method checks whether the SqlConnection is open or not. The whole synchronization issue is hidden from the client application using the DBConnectionSingleton object instance.



Politica de confidentialitate | Termeni si conditii de utilizare



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 752
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved