using System.Data.ProviderBase;
#if !MOBILE
using System.Data.Odbc;
-#endif
using System.Data.OleDb;
+#endif
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Diagnostics;
FileIOPermission.RevertAssert();
}
}
-#if !MOBILE
+#if MOBILE
+ static internal object LocalMachineRegistryValue(string subkey, string queryvalue) {
+ return null;
+ }
+#else
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
static internal Stream GetXmlStreamFromValues(String[] values, String errorString) {
internal static class NativeMethods {
+#if !NO_OLEDB
[Guid("0c733a1e-2a1c-11ce-ade5-00aa0044773d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport]
internal interface ISourcesRowset {
[In] IntPtr rgProperties,
[Out, MarshalAs(UnmanagedType.Interface)] out object ppRowset);
}
+#endif
[Guid("0C733A5E-2A1C-11CE-ADE5-00AA0044773D"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown), ComImport]
internal interface ITransactionJoin {
}
}
-
+#if !NO_ODBC
//
// Manually edited wrappers
//
if (((System.Data.Odbc.ODBC32.RetCode.SUCCESS != a1) || (modFlags & ApiGroup.StatusOk) != 0) && (modFlags & ApiGroup.Trace) != 0 && modID != NoData)
NativeMethods.Trace (modID, UIntPtr.Zero, UIntPtr.Zero, fmtPrintfW, (int)(short)a1, a2);
}
+#endif
+#if !NO_OLEDB
[BidMethod]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static void Trace(string fmtPrintfW, System.Data.OleDb.OleDbHResult a1) { //
if ((modFlags & ApiGroup.Trace) != 0 && modID != NoData)
NativeMethods.Trace (modID, UIntPtr.Zero, UIntPtr.Zero, fmtPrintfW, (int)a1,a2);
}
-
+#endif
[BidMethod]
internal static void Trace(string fmtPrintfW, System.String a1, System.String a2) {
//------------------------------------------------------------------------------
using System;
+#if !NO_ODBC
using System.Data.Odbc;
+#endif
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
[SuppressUnmanagedCodeSecurityAttribute()]
internal static class UnsafeNativeMethods {
+#if !NO_ODBC
//
// ODBC32
//
[In, MarshalAs(UnmanagedType.LPWStr)]
/*SQLCHAR* */string TableType,
/*SQLSMALLINT*/Int16 NameLen4);
+#endif
+#if !NO_OLEDB
//
// Oleaut32
//
IntPtr pUnkOuter,
ref Guid riid,
[MarshalAs(UnmanagedType.Interface)] ref object ppCommand);
+#endif
//
// Advapi32.dll Integrated security functions
using System.Collections.Specialized;
using System.Xml;
using System.Xml.Serialization;
+#if !NO_CONFIGURATION
using System.Xml.Serialization.Advanced;
+#endif
using System.Xml.Schema;
using System.Runtime.Serialization.Formatters.Binary; //Binary Formatter
using System.CodeDom;
private static bool PublishLegacyWSDL()
{
Single version = 1.0f; // Default is Version 1.0
+#if !NO_CONFIGURATION
NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection(Keywords.WS_DATASETFULLQNAME);
if (settings != null)
{
version = Single.Parse(values[0], CultureInfo.InvariantCulture);
}
}
+#endif
return (version < 2.0f); // if config does not exist, Default is Version 1.0
}
}
+#if !NO_CODEDOM
public class DataSetSchemaImporterExtension : SchemaImporterExtension {
// DataSetSchemaImporterExtension is used for WebServices, it is used to recognize the schema of DataSet within wsdl
// If a non 2.0 enabled DataSetSchemaImporterExtension, wsdl will generate a classes that you can't cast to dataset / datatable
return false;
}
}
+#endif
}
DbConnectionInternal newConnection = CreateConnection(connectionOptions, poolKey, poolGroupProviderInfo, null, owningConnection, userOptions);
if (null != newConnection) {
+#if !MOBILE
PerformanceCounters.HardConnectsPerSecond.Increment();
+#endif
newConnection.MakeNonPooledObject(owningConnection, PerformanceCounters);
}
Bid.Trace("<prov.DbConnectionFactory.CreateNonPooledConnection|RES|CPOOL> %d#, Non-pooled database connection created.\n", ObjectID);
DbConnectionInternal newConnection = CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningObject, userOptions);
if (null != newConnection) {
+#if !MOBILE
PerformanceCounters.HardConnectsPerSecond.Increment();
+#endif
newConnection.MakePooledConnection(pool);
}
Bid.Trace("<prov.DbConnectionFactory.CreatePooledConnection|RES|CPOOL> %d#, Pooled database connection created.\n", ObjectID);
}
else {
if (retry.TrySetResult(task.Result)) {
+#if !MOBILE
PerformanceCounters.NumberOfNonPooledConnections.Increment();
+#endif
}
else {
// The outer TaskCompletionSource was already completed
}
connection = CreateNonPooledConnection(owningConnection, poolGroup, userOptions);
+#if !MOBILE
PerformanceCounters.NumberOfNonPooledConnections.Increment();
+#endif
}
else {
if (owningConnection.ForceNewConnection) {
// lock prevents race condition with PruneConnectionPoolGroups
newConnectionPoolGroups.Add(key, newConnectionPoolGroup);
+#if !MOBILE
PerformanceCounters.NumberOfActiveConnectionPoolGroups.Increment();
+#endif
connectionPoolGroup = newConnectionPoolGroup;
_connectionPoolGroups = newConnectionPoolGroups;
}
if (Bid.AdvancedOn) {
Bid.Trace("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> %d#, ReleasePool=%d#\n", ObjectID, pool.ObjectID);
}
+#if !MOBILE
PerformanceCounters.NumberOfInactiveConnectionPools.Decrement();
+#endif
}
}
}
if (Bid.AdvancedOn) {
Bid.Trace("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> %d#, ReleasePoolGroup=%d#\n", ObjectID, poolGroup.ObjectID);
}
+#if !MOBILE
PerformanceCounters.NumberOfInactiveConnectionPoolGroups.Decrement();
+#endif
}
}
}
// move idle entries from last prune pass to a queue for pending release
// otherwise process entry which may move it from active to idle
if (entry.Value.Prune()) { // may add entries to _poolsToRelease
+#if !MOBILE
PerformanceCounters.NumberOfActiveConnectionPoolGroups.Decrement();
+#endif
QueuePoolGroupForRelease(entry.Value);
}
else {
}
_poolsToRelease.Add(pool);
}
+#if !MOBILE
PerformanceCounters.NumberOfInactiveConnectionPools.Increment();
+#endif
}
internal void QueuePoolGroupForRelease(DbConnectionPoolGroup poolGroup) {
lock (_poolGroupsToRelease) {
_poolGroupsToRelease.Add(poolGroup);
}
+#if !MOBILE
PerformanceCounters.NumberOfInactiveConnectionPoolGroups.Increment();
+#endif
}
virtual protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) {
partial void RepairInnerConnection();
+#if !MOBILE
// NOTE: This is just a private helper because OracleClient V1.1 shipped
// with a different argument name and it's a breaking change to not use
// the same argument names in V2.0 (VB Named Parameter Binding--Ick)
// we should consider a GC.KeepAlive(this) here.
GC.KeepAlive(this);
}
+#endif
override public void EnlistTransaction(SysTx.Transaction transaction) {
CONNECTIONOBJECTNAME.ExecutePermission.Demand();
Activate(transaction);
+#if !MOBILE
PerformanceCounters.NumberOfActiveConnections.Increment();
+#endif
}
internal void AddWeakReference(object value, int tag) {
else {
Deactivate(); // ensure we de-activate non-pooled connections, or the data readers and transactions may not get cleaned up...
+#if !MOBILE
PerformanceCounters.HardDisconnectsPerSecond.Increment();
+#endif
// To prevent an endless recursion, we need to clear
// the owning object before we call dispose so that
SetInStasis();
}
else {
+#if !MOBILE
PerformanceCounters.NumberOfNonPooledConnections.Decrement();
+#endif
if (this.GetType() != typeof(System.Data.SqlClient.SqlInternalConnectionSmi))
{
Dispose();
Debug.Assert(0 == activateCount, "activated multiple times?");
#endif // DEBUG
+#if !MOBILE
if (PerformanceCounters != null) { // Pool.Clear will DestroyObject that will clean performanceCounters before going here
PerformanceCounters.NumberOfActiveConnections.Decrement();
}
+#endif
if (!_connectionIsDoomed && Pool.UseLoadBalancing) {
// If we're not already doomed, check the connection's lifetime and
// once and for all, or the server will have fits about us
// leaving connections open until the client-side GC kicks
// in.
+#if !MOBILE
PerformanceCounters.NumberOfNonPooledConnections.Decrement();
+#endif
Dispose();
}
// When _pooledCount is 0, the connection is a pooled connection
internal void SetInStasis() {
_isInStasis = true;
Bid.PoolerTrace("<prov.DbConnectionInternal.SetInStasis|RES|CPOOL> %d#, Non-Pooled Connection has Delegated Transaction, waiting to Dispose.\n", ObjectID);
+#if !MOBILE
PerformanceCounters.NumberOfStasisConnections.Increment();
+#endif
}
private void TerminateStasis(bool returningToPool) {
else {
Bid.PoolerTrace("<prov.DbConnectionInternal.TerminateStasis|RES|CPOOL> %d#, Delegated Transaction has ended, connection is closed/leaked. Disposing.\n", ObjectID);
}
+#if !MOBILE
PerformanceCounters.NumberOfStasisConnections.Decrement();
+#endif
_isInStasis = false;
}
Bid.PoolerTrace("<prov.DbConnectionPool.TransactedConnectionPool.PutTransactedObject|RES|CPOOL> %d#, Transaction %d#, Connection %d#, Added.\n", ObjectID, transaction.GetHashCode(), transactedObject.ObjectID );
}
+#if !MOBILE
Pool.PerformanceCounters.NumberOfFreeConnections.Increment();
-
+#endif
}
internal void TransactionEnded(SysTx.Transaction transaction, DbConnectionInternal transactedObject)
// connections, we'll put it back...
if (0 <= entry)
{
+#if !MOBILE
Pool.PerformanceCounters.NumberOfFreeConnections.Decrement();
+#endif
Pool.PutObjectFromTransactedPool(transactedObject);
}
}
if (_stackOld.TryPop(out obj)) {
Debug.Assert(obj != null, "null connection is not expected");
// If we obtained one from the old stack, destroy it.
+#if !MOBILE
PerformanceCounters.NumberOfFreeConnections.Decrement();
+#endif
// Transaction roots must survive even aging out (TxEnd event will clean them up).
bool shouldDestroy = true;
// Second, dispose of all the free connections.
while (_stackNew.TryPop(out obj)) {
Debug.Assert(obj != null, "null connection is not expected");
+#if !MOBILE
PerformanceCounters.NumberOfFreeConnections.Decrement();
+#endif
DestroyObject(obj);
}
while (_stackOld.TryPop(out obj)) {
Debug.Assert(obj != null, "null connection is not expected");
+#if !MOBILE
PerformanceCounters.NumberOfFreeConnections.Decrement();
+#endif
DestroyObject(obj);
}
}
_objectList.Add(newObj);
_totalObjects = _objectList.Count;
+#if !MOBILE
PerformanceCounters.NumberOfPooledConnections.Increment(); //
+#endif
}
// If the old connection belonged to another pool, we need to remove it from that
if (removed) {
Bid.PoolerTrace("<prov.DbConnectionPool.DestroyObject|RES|CPOOL> %d#, Connection %d#, Removed from pool.\n", ObjectID, obj.ObjectID);
+#if !MOBILE
PerformanceCounters.NumberOfPooledConnections.Decrement();
+#endif
}
obj.Dispose();
Bid.PoolerTrace("<prov.DbConnectionPool.DestroyObject|RES|CPOOL> %d#, Connection %d#, Disposed.\n", ObjectID, obj.ObjectID);
+#if !MOBILE
PerformanceCounters.HardDisconnectsPerSecond.Increment();
+#endif
}
}
DbConnectionInternal obj = null;
SysTx.Transaction transaction = null;
+#if !MOBILE
PerformanceCounters.SoftConnectsPerSecond.Increment();
+#endif
Bid.PoolerTrace("<prov.DbConnectionPool.GetConnection|RES|CPOOL> %d#, Getting connection.\n", ObjectID);
/// <param name="oldConnection">Inner connection that will be replaced</param>
/// <returns>A new inner connection that is attached to the <paramref name="owningObject"/></returns>
internal DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) {
+#if !MOBILE
PerformanceCounters.SoftConnectsPerSecond.Increment();
+#endif
Bid.PoolerTrace("<prov.DbConnectionPool.ReplaceConnection|RES|CPOOL> %d#, replacing connection.\n", ObjectID);
DbConnectionInternal newConnection = UserCreateRequest(owningObject, userOptions, oldConnection);
if (null != obj) {
Bid.PoolerTrace("<prov.DbConnectionPool.GetFromGeneralPool|RES|CPOOL> %d#, Connection %d#, Popped from general pool.\n", ObjectID, obj.ObjectID);
+#if !MOBILE
PerformanceCounters.NumberOfFreeConnections.Decrement();
+#endif
}
return(obj);
}
if (null != obj) {
Bid.PoolerTrace("<prov.DbConnectionPool.GetFromTransactedPool|RES|CPOOL> %d#, Connection %d#, Popped from transacted pool.\n", ObjectID, obj.ObjectID);
+#if !MOBILE
PerformanceCounters.NumberOfFreeConnections.Decrement();
+#endif
if (obj.IsTransactionRoot) {
try {
_stackNew.Push(obj);
_waitHandles.PoolSemaphore.Release(1);
+#if !MOBILE
PerformanceCounters.NumberOfFreeConnections.Increment();
-
+#endif
}
internal void PutObject(DbConnectionInternal obj, object owningObject) {
Debug.Assert(null != obj, "null obj?");
+#if !MOBILE
PerformanceCounters.SoftDisconnectsPerSecond.Increment();
+#endif
// Once a connection is closing (which is the state that we're in at
// this point in time) you cannot delegate a transaction to or enlist
DbConnectionInternal obj = reclaimedObjects[i];
Bid.PoolerTrace("<prov.DbConnectionPool.ReclaimEmancipatedObjects|RES|CPOOL> %d#, Connection %d#, Reclaiming.\n", ObjectID, obj.ObjectID);
+#if !MOBILE
PerformanceCounters.NumberOfReclaimedConnections.Increment();
+#endif
emancipatedObjectFound = true;
DbConnectionFactory connectionFactory = pool.ConnectionFactory;
+#if !MOBILE
connectionFactory.PerformanceCounters.NumberOfActiveConnectionPools.Decrement();
+#endif
connectionFactory.QueuePoolForRelease(pool, true);
}
}
newPool.Startup(); // must start pool before usage
bool addResult = _poolCollection.TryAdd(currentIdentity, newPool);
Debug.Assert(addResult, "No other pool with current identity should exist at this point");
+#if !MOBILE
connectionFactory.PerformanceCounters.NumberOfActiveConnectionPools.Increment();
+#endif
pool = newPool;
newPool = null;
}
// are completely empty.
DbConnectionFactory connectionFactory = pool.ConnectionFactory;
+#if !MOBILE
connectionFactory.PerformanceCounters.NumberOfActiveConnectionPools.Decrement();
+#endif
connectionFactory.QueuePoolForRelease(pool, false);
}
else {
bRevertAssert = true;
System.Diagnostics.Debug.Assert ( m_fs == null );
+#if MOBILE
+ m_fs = new System.IO.FileStream ( hFile.DangerousGetHandle (), access, ( ( options & System.IO.FileOptions.Asynchronous ) != 0 ), DefaultBufferSize );
+#else
m_fs = new System.IO.FileStream ( hFile, access, DefaultBufferSize, ( ( options & System.IO.FileOptions.Asynchronous ) != 0 ) );
+#endif
}
finally
{
if (s_configurableInstances == null)
{
Dictionary<string, InstanceInfo> tempConfigurableInstances = new Dictionary<string, InstanceInfo>(StringComparer.OrdinalIgnoreCase);
+#if !NO_CONFIGURATION
object section = PrivilegedConfigurationManager.GetSection("system.data.localdb");
if (section != null) // if no section just skip creation
{
}
}
else
+#endif
Bid.Trace( "<sc.LocalDBAPI.CreateLocalDBInstance> No system.data.localdb section found in configuration");
s_configurableInstances = tempConfigurableInstances;
}
}
}
+#if !MOBILE
public void EnlistDistributedTransaction(System.EnterpriseServices.ITransaction transaction) {
if (IsContextConnection) {
throw SQL.NotAvailableOnContextConnection();
EnlistDistributedTransactionHelper(transaction);
}
+#endif
override public void Open() {
IntPtr hscp;
throw SQL.NotAvailableOnContextConnection();
}
- NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.sqlclient");
Stream XMLStream =null;
+#if !NO_CONFIGURATION
+ NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.sqlclient");
if (settings != null){
string [] values = settings.GetValues(_metaDataXml);
if (values != null) {
XMLStream = ADP.GetXmlStreamFromValues(values, _metaDataXml);
}
}
+#endif
// if the xml was not obtained from machine.config use the embedded XML resource
if (XMLStream == null){
public static readonly SqlPerformanceCounters SingletonInstance = new SqlPerformanceCounters();
+#if !MOBILE
[System.Diagnostics.PerformanceCounterPermissionAttribute(System.Security.Permissions.SecurityAction.Assert, PermissionAccess=PerformanceCounterPermissionAccess.Write, MachineName=".", CategoryName=CategoryName)]
private SqlPerformanceCounters() : base (CategoryName, CategoryHelp) {
}
+#endif
}
}
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
static internal void AliasRegistryLookup(ref string host, ref string protocol) {
+#if !MOBILE
if (!ADP.IsEmpty(host)) {
const String folder = "SOFTWARE\\Microsoft\\MSSQLServer\\Client\\ConnectTo";
// Put a try...catch... around this so we don't abort ANY connection if we can't read the registry.
}
}
}
+#endif
}
// Encrypt password to be sent to SQL Server