Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Data / System / Data / Odbc / OdbcConnectionFactory.cs / 1 / OdbcConnectionFactory.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.Odbc
{
using System;
using System.Data.Common;
using System.Data.ProviderBase;
using System.Diagnostics;
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
sealed internal class OdbcConnectionFactory : DbConnectionFactory {
private OdbcConnectionFactory() : base() {}
// At this time, the ODBC Provider doesn't have any connection pool counters
// because we'd only confuse people with "non-pooled" connections that are
// actually being pooled by the native pooler.
private const string _MetaData = ":MetaDataXml";
private const string _defaultMetaDataXml = "defaultMetaDataXml";
public static readonly OdbcConnectionFactory SingletonInstance = new OdbcConnectionFactory();
override public DbProviderFactory ProviderFactory {
get {
return OdbcFactory.Instance;
}
}
override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) {
DbConnectionInternal result = new OdbcConnectionOpen(owningObject as OdbcConnection, options as OdbcConnectionString);
return result;
}
override protected DbConnectionOptions CreateConnectionOptions(string connectionString, DbConnectionOptions previous) {
Debug.Assert(!ADP.IsEmpty(connectionString), "empty connectionString");
OdbcConnectionString result = new OdbcConnectionString(connectionString, (null != previous));
return result;
}
override protected DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions( DbConnectionOptions connectionOptions ) {
// At this time, the ODBC provider only supports native pooling so we
// simply return NULL to indicate that.
return null;
}
override internal DbConnectionPoolGroupProviderInfo CreateConnectionPoolGroupProviderInfo (DbConnectionOptions connectionOptions) {
return new OdbcConnectionPoolGroupProviderInfo();
}
override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory){
Debug.Assert (internalConnection != null,"internalConnection may not be null.");
cacheMetaDataFactory = false;
OdbcConnection odbcOuterConnection = ((OdbcConnectionOpen)internalConnection).OuterConnection;
Debug.Assert(odbcOuterConnection != null,"outer connection may not be null.");
NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.odbc");
Stream XMLStream =null;
// get the DBMS Name
object driverName = null;
string stringValue = odbcOuterConnection.GetInfoStringUnhandled(ODBC32.SQL_INFO.DRIVER_NAME);
if (stringValue != null) {
driverName = stringValue;
}
if (settings != null){
string [] values = null;
string metaDataXML = null;
// first try to get the provider specific xml
// if driver name is not supported we can't build the settings key needed to
// get the provider specific XML path
if (driverName != null){
metaDataXML = ((string)driverName) + _MetaData;
values = settings.GetValues(metaDataXML);
}
// if we did not find provider specific xml see if there is new default xml
if (values == null) {
metaDataXML = _defaultMetaDataXml;
values = settings.GetValues(metaDataXML);
}
// If there is an XML file get it
if (values != null) {
XMLStream = ADP.GetXmlStreamFromValues(values,metaDataXML);
}
}
// use the embedded xml if the user did not over ride it
if (XMLStream == null){
XMLStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.Odbc.OdbcMetaData.xml");
cacheMetaDataFactory = true;
}
Debug.Assert (XMLStream != null,"XMLstream may not be null.");
String versionString = odbcOuterConnection.GetInfoStringUnhandled(ODBC32.SQL_INFO.DBMS_VER);
return new OdbcMetaDataFactory (XMLStream,
versionString,
versionString,
odbcOuterConnection);
}
override internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnection connection) {
OdbcConnection c = (connection as OdbcConnection);
if (null != c) {
return c.PoolGroup;
}
return null;
}
override internal DbConnectionInternal GetInnerConnection(DbConnection connection) {
OdbcConnection c = (connection as OdbcConnection);
if (null != c) {
return c.InnerConnection;
}
return null;
}
override protected int GetObjectId(DbConnection connection) {
OdbcConnection c = (connection as OdbcConnection);
if (null != c) {
return c.ObjectID;
}
return 0;
}
override internal void PermissionDemand(DbConnection outerConnection) {
OdbcConnection c = (outerConnection as OdbcConnection);
if (null != c) {
c.PermissionDemand();
}
}
override internal void SetConnectionPoolGroup(DbConnection outerConnection, DbConnectionPoolGroup poolGroup) {
OdbcConnection c = (outerConnection as OdbcConnection);
if (null != c) {
c.PoolGroup = poolGroup;
}
}
override internal void SetInnerConnectionEvent(DbConnection owningObject, DbConnectionInternal to) {
OdbcConnection c = (owningObject as OdbcConnection);
if (null != c) {
c.SetInnerConnectionEvent(to);
}
}
override internal bool SetInnerConnectionFrom(DbConnection owningObject, DbConnectionInternal to, DbConnectionInternal from) {
OdbcConnection c = (owningObject as OdbcConnection);
if (null != c) {
return c.SetInnerConnectionFrom(to, from);
}
return false;
}
override internal void SetInnerConnectionTo(DbConnection owningObject, DbConnectionInternal to) {
OdbcConnection c = (owningObject as OdbcConnection);
if (null != c) {
c.SetInnerConnectionTo(to);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.Odbc
{
using System;
using System.Data.Common;
using System.Data.ProviderBase;
using System.Diagnostics;
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
sealed internal class OdbcConnectionFactory : DbConnectionFactory {
private OdbcConnectionFactory() : base() {}
// At this time, the ODBC Provider doesn't have any connection pool counters
// because we'd only confuse people with "non-pooled" connections that are
// actually being pooled by the native pooler.
private const string _MetaData = ":MetaDataXml";
private const string _defaultMetaDataXml = "defaultMetaDataXml";
public static readonly OdbcConnectionFactory SingletonInstance = new OdbcConnectionFactory();
override public DbProviderFactory ProviderFactory {
get {
return OdbcFactory.Instance;
}
}
override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) {
DbConnectionInternal result = new OdbcConnectionOpen(owningObject as OdbcConnection, options as OdbcConnectionString);
return result;
}
override protected DbConnectionOptions CreateConnectionOptions(string connectionString, DbConnectionOptions previous) {
Debug.Assert(!ADP.IsEmpty(connectionString), "empty connectionString");
OdbcConnectionString result = new OdbcConnectionString(connectionString, (null != previous));
return result;
}
override protected DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions( DbConnectionOptions connectionOptions ) {
// At this time, the ODBC provider only supports native pooling so we
// simply return NULL to indicate that.
return null;
}
override internal DbConnectionPoolGroupProviderInfo CreateConnectionPoolGroupProviderInfo (DbConnectionOptions connectionOptions) {
return new OdbcConnectionPoolGroupProviderInfo();
}
override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory){
Debug.Assert (internalConnection != null,"internalConnection may not be null.");
cacheMetaDataFactory = false;
OdbcConnection odbcOuterConnection = ((OdbcConnectionOpen)internalConnection).OuterConnection;
Debug.Assert(odbcOuterConnection != null,"outer connection may not be null.");
NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.odbc");
Stream XMLStream =null;
// get the DBMS Name
object driverName = null;
string stringValue = odbcOuterConnection.GetInfoStringUnhandled(ODBC32.SQL_INFO.DRIVER_NAME);
if (stringValue != null) {
driverName = stringValue;
}
if (settings != null){
string [] values = null;
string metaDataXML = null;
// first try to get the provider specific xml
// if driver name is not supported we can't build the settings key needed to
// get the provider specific XML path
if (driverName != null){
metaDataXML = ((string)driverName) + _MetaData;
values = settings.GetValues(metaDataXML);
}
// if we did not find provider specific xml see if there is new default xml
if (values == null) {
metaDataXML = _defaultMetaDataXml;
values = settings.GetValues(metaDataXML);
}
// If there is an XML file get it
if (values != null) {
XMLStream = ADP.GetXmlStreamFromValues(values,metaDataXML);
}
}
// use the embedded xml if the user did not over ride it
if (XMLStream == null){
XMLStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.Odbc.OdbcMetaData.xml");
cacheMetaDataFactory = true;
}
Debug.Assert (XMLStream != null,"XMLstream may not be null.");
String versionString = odbcOuterConnection.GetInfoStringUnhandled(ODBC32.SQL_INFO.DBMS_VER);
return new OdbcMetaDataFactory (XMLStream,
versionString,
versionString,
odbcOuterConnection);
}
override internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnection connection) {
OdbcConnection c = (connection as OdbcConnection);
if (null != c) {
return c.PoolGroup;
}
return null;
}
override internal DbConnectionInternal GetInnerConnection(DbConnection connection) {
OdbcConnection c = (connection as OdbcConnection);
if (null != c) {
return c.InnerConnection;
}
return null;
}
override protected int GetObjectId(DbConnection connection) {
OdbcConnection c = (connection as OdbcConnection);
if (null != c) {
return c.ObjectID;
}
return 0;
}
override internal void PermissionDemand(DbConnection outerConnection) {
OdbcConnection c = (outerConnection as OdbcConnection);
if (null != c) {
c.PermissionDemand();
}
}
override internal void SetConnectionPoolGroup(DbConnection outerConnection, DbConnectionPoolGroup poolGroup) {
OdbcConnection c = (outerConnection as OdbcConnection);
if (null != c) {
c.PoolGroup = poolGroup;
}
}
override internal void SetInnerConnectionEvent(DbConnection owningObject, DbConnectionInternal to) {
OdbcConnection c = (owningObject as OdbcConnection);
if (null != c) {
c.SetInnerConnectionEvent(to);
}
}
override internal bool SetInnerConnectionFrom(DbConnection owningObject, DbConnectionInternal to, DbConnectionInternal from) {
OdbcConnection c = (owningObject as OdbcConnection);
if (null != c) {
return c.SetInnerConnectionFrom(to, from);
}
return false;
}
override internal void SetInnerConnectionTo(DbConnection owningObject, DbConnectionInternal to) {
OdbcConnection c = (owningObject as OdbcConnection);
if (null != c) {
c.SetInnerConnectionTo(to);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GAC.cs
- DataServiceProviderWrapper.cs
- BitStream.cs
- WebPartConnectionsEventArgs.cs
- MetadataImporter.cs
- IPEndPoint.cs
- AnimationStorage.cs
- DefaultAuthorizationContext.cs
- SQLBoolean.cs
- Tile.cs
- UnSafeCharBuffer.cs
- AddInProcess.cs
- WorkflowElementDialogWindow.xaml.cs
- PriorityQueue.cs
- SqlConnectionFactory.cs
- HTMLTextWriter.cs
- InternalCache.cs
- IDReferencePropertyAttribute.cs
- RenderingEventArgs.cs
- AsymmetricCryptoHandle.cs
- PatternMatchRules.cs
- DeleteStoreRequest.cs
- XmlMapping.cs
- SecUtil.cs
- __ComObject.cs
- LayoutInformation.cs
- ReflectionUtil.cs
- DataServiceResponse.cs
- JsonSerializer.cs
- __ComObject.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- autovalidator.cs
- EntityDataSourceStatementEditor.cs
- EntitySet.cs
- ConfigurationSectionCollection.cs
- ClientTarget.cs
- NavigationHelper.cs
- DataList.cs
- UDPClient.cs
- FormViewPagerRow.cs
- BrowserDefinition.cs
- FormatConvertedBitmap.cs
- SplineKeyFrames.cs
- CFGGrammar.cs
- NavigationHelper.cs
- TableCell.cs
- CollaborationHelperFunctions.cs
- ColorDialog.cs
- SessionParameter.cs
- GridViewColumnCollection.cs
- InvalidOperationException.cs
- CardSpacePolicyElement.cs
- SqlWorkflowInstanceStore.cs
- SqlNode.cs
- RadioButtonPopupAdapter.cs
- AssemblyBuilder.cs
- ToolboxSnapDragDropEventArgs.cs
- PartialList.cs
- ExtensionSimplifierMarkupObject.cs
- LineServicesCallbacks.cs
- NodeLabelEditEvent.cs
- HttpsTransportElement.cs
- AutoGeneratedField.cs
- PointAnimationClockResource.cs
- BreakSafeBase.cs
- PrimitiveType.cs
- TCPListener.cs
- RawKeyboardInputReport.cs
- ItemsPanelTemplate.cs
- UnaryExpression.cs
- ComboBoxAutomationPeer.cs
- ChtmlTextWriter.cs
- OperandQuery.cs
- FlowDocumentPaginator.cs
- ConnectionStringsExpressionBuilder.cs
- RoutedEventArgs.cs
- LambdaCompiler.Logical.cs
- MulticastNotSupportedException.cs
- DeviceContext.cs
- Pens.cs
- LoginAutoFormat.cs
- SqlDataRecord.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- SettingsAttributes.cs
- BlockUIContainer.cs
- WorkflowViewStateService.cs
- MultiBinding.cs
- HtmlFormWrapper.cs
- UIPropertyMetadata.cs
- JapaneseCalendar.cs
- X509ThumbprintKeyIdentifierClause.cs
- ExpressionBuilderContext.cs
- SimpleHandlerBuildProvider.cs
- TabItemAutomationPeer.cs
- IdentityNotMappedException.cs
- IgnoreSectionHandler.cs
- OperationInvokerBehavior.cs
- SecurityPermission.cs
- RuntimeHandles.cs
- TransformationRules.cs