Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Data / System / Data / Sql / SqlDataSourceEnumerator.cs / 1 / SqlDataSourceEnumerator.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.Sql {
using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
#if WINFSInternalOnly
internal
#else
public
#endif
sealed class SqlDataSourceEnumerator : DbDataSourceEnumerator {
private static readonly SqlDataSourceEnumerator SingletonInstance = new SqlDataSourceEnumerator();
internal const string ServerName = "ServerName";
internal const string InstanceName = "InstanceName";
internal const string IsClustered = "IsClustered";
internal const string Version = "Version";
private const int timeoutSeconds = ADP.DefaultCommandTimeout;
private long timeoutTime; // variable used for timeout computations, holds the value of the hi-res performance counter at which this request should expire
private SqlDataSourceEnumerator() : base() {
}
public static SqlDataSourceEnumerator Instance {
get {
return SqlDataSourceEnumerator.SingletonInstance;
}
}
override public DataTable GetDataSources() {
(new NamedPermissionSet("FullTrust")).Demand(); // SQLBUDT 244304
char[] buffer = null;
StringBuilder strbldr = new StringBuilder();
Int32 bufferSize = 1024;
Int32 readLength = 0;
buffer = new char[bufferSize];
bool more = true;
bool failure = false;
IntPtr handle = ADP.PtrZero;
RuntimeHelpers.PrepareConstrainedRegions();
try {
timeoutTime = TdsParserStaticMethods.GetTimeoutSeconds(timeoutSeconds);
RuntimeHelpers.PrepareConstrainedRegions();
try {} finally {
handle = SNINativeMethodWrapper.SNIServerEnumOpen();
}
if (ADP.PtrZero != handle) {
while (more && !TdsParserStaticMethods.TimeoutHasExpired(timeoutTime)) {
// readLength = UnsafeNativeMethods.SNIServerEnumReadEx(handle, buffer, bufferSize, ref more, TdsParserStaticMethods.GetTimeoutMilliseconds(timeoutTime));
readLength = SNINativeMethodWrapper.SNIServerEnumRead(handle, buffer, bufferSize, ref more);
if (readLength > bufferSize) {
failure = true;
more = false;
}
else if (0 < readLength) {
strbldr.Append(buffer, 0, readLength);
}
}
}
}
finally {
if (ADP.PtrZero != handle) {
SNINativeMethodWrapper.SNIServerEnumClose(handle);
}
}
if (failure) {
Debug.Assert(false, "GetDataSources:SNIServerEnumRead returned bad length");
Bid.Trace(" GetDataSources:SNIServerEnumRead returned bad length, requested %d, received %d", bufferSize, readLength);
throw ADP.ArgumentOutOfRange("readLength");
}
return ParseServerEnumString(strbldr.ToString());
}
private static string _Version = "Version:";
private static string _Cluster = "Clustered:";
private static int _clusterLength = _Cluster.Length;
private static int _versionLength =_Version.Length;
static private DataTable ParseServerEnumString(string serverInstances) {
DataTable dataTable = new DataTable("SqlDataSources");
dataTable.Locale = CultureInfo.InvariantCulture;
dataTable.Columns.Add(ServerName, typeof(string));
dataTable.Columns.Add(InstanceName, typeof(string));
dataTable.Columns.Add(IsClustered, typeof(string));
dataTable.Columns.Add(Version, typeof(string));
DataRow dataRow = null;
string serverName = null;
string instanceName = null;
string isClustered = null;
string version = null;
// Every row comes in the format "serverName\instanceName;Clustered:[Yes|No];Version:.."
// Every row is terminated by a null character.
// Process one row at a time
foreach (string instance in serverInstances.Split('\0')) {
string value = instance.Trim('\0'); // MDAC 91934
if (0 == value.Length) {
continue;
}
foreach (string instance2 in value.Split(';')) {
if (serverName == null) {
foreach(string instance3 in instance2.Split('\\')) {
if (serverName == null) {
serverName = instance3;
continue;
}
Debug.Assert(instanceName == null);
instanceName = instance3;
}
continue;
}
if (isClustered == null) {
Debug.Assert(String.Compare(_Cluster, 0, instance2, 0, _clusterLength, StringComparison.OrdinalIgnoreCase) == 0);
isClustered = instance2.Substring(_clusterLength);
continue;
}
Debug.Assert(version == null);
Debug.Assert(String.Compare(_Version, 0, instance2, 0, _versionLength, StringComparison.OrdinalIgnoreCase) == 0);
version = instance2.Substring(_versionLength);
}
string query = "ServerName='"+serverName+"'";
if (!ADP.IsEmpty(instanceName)) { // SQL BU DT 20006584: only append instanceName if present.
query += " AND InstanceName='"+instanceName+"'";
}
// SNI returns dupes - do not add them. SQL BU DT 290323
if (dataTable.Select(query).Length == 0) {
dataRow = dataTable.NewRow();
dataRow[0] = serverName;
dataRow[1] = instanceName;
dataRow[2] = isClustered;
dataRow[3] = version;
dataTable.Rows.Add(dataRow);
}
serverName = null;
instanceName = null;
isClustered = null;
version = null;
}
foreach(DataColumn column in dataTable.Columns) {
column.ReadOnly = true;
}
return dataTable;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.Sql {
using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
#if WINFSInternalOnly
internal
#else
public
#endif
sealed class SqlDataSourceEnumerator : DbDataSourceEnumerator {
private static readonly SqlDataSourceEnumerator SingletonInstance = new SqlDataSourceEnumerator();
internal const string ServerName = "ServerName";
internal const string InstanceName = "InstanceName";
internal const string IsClustered = "IsClustered";
internal const string Version = "Version";
private const int timeoutSeconds = ADP.DefaultCommandTimeout;
private long timeoutTime; // variable used for timeout computations, holds the value of the hi-res performance counter at which this request should expire
private SqlDataSourceEnumerator() : base() {
}
public static SqlDataSourceEnumerator Instance {
get {
return SqlDataSourceEnumerator.SingletonInstance;
}
}
override public DataTable GetDataSources() {
(new NamedPermissionSet("FullTrust")).Demand(); // SQLBUDT 244304
char[] buffer = null;
StringBuilder strbldr = new StringBuilder();
Int32 bufferSize = 1024;
Int32 readLength = 0;
buffer = new char[bufferSize];
bool more = true;
bool failure = false;
IntPtr handle = ADP.PtrZero;
RuntimeHelpers.PrepareConstrainedRegions();
try {
timeoutTime = TdsParserStaticMethods.GetTimeoutSeconds(timeoutSeconds);
RuntimeHelpers.PrepareConstrainedRegions();
try {} finally {
handle = SNINativeMethodWrapper.SNIServerEnumOpen();
}
if (ADP.PtrZero != handle) {
while (more && !TdsParserStaticMethods.TimeoutHasExpired(timeoutTime)) {
// readLength = UnsafeNativeMethods.SNIServerEnumReadEx(handle, buffer, bufferSize, ref more, TdsParserStaticMethods.GetTimeoutMilliseconds(timeoutTime));
readLength = SNINativeMethodWrapper.SNIServerEnumRead(handle, buffer, bufferSize, ref more);
if (readLength > bufferSize) {
failure = true;
more = false;
}
else if (0 < readLength) {
strbldr.Append(buffer, 0, readLength);
}
}
}
}
finally {
if (ADP.PtrZero != handle) {
SNINativeMethodWrapper.SNIServerEnumClose(handle);
}
}
if (failure) {
Debug.Assert(false, "GetDataSources:SNIServerEnumRead returned bad length");
Bid.Trace(" GetDataSources:SNIServerEnumRead returned bad length, requested %d, received %d", bufferSize, readLength);
throw ADP.ArgumentOutOfRange("readLength");
}
return ParseServerEnumString(strbldr.ToString());
}
private static string _Version = "Version:";
private static string _Cluster = "Clustered:";
private static int _clusterLength = _Cluster.Length;
private static int _versionLength =_Version.Length;
static private DataTable ParseServerEnumString(string serverInstances) {
DataTable dataTable = new DataTable("SqlDataSources");
dataTable.Locale = CultureInfo.InvariantCulture;
dataTable.Columns.Add(ServerName, typeof(string));
dataTable.Columns.Add(InstanceName, typeof(string));
dataTable.Columns.Add(IsClustered, typeof(string));
dataTable.Columns.Add(Version, typeof(string));
DataRow dataRow = null;
string serverName = null;
string instanceName = null;
string isClustered = null;
string version = null;
// Every row comes in the format "serverName\instanceName;Clustered:[Yes|No];Version:.."
// Every row is terminated by a null character.
// Process one row at a time
foreach (string instance in serverInstances.Split('\0')) {
string value = instance.Trim('\0'); // MDAC 91934
if (0 == value.Length) {
continue;
}
foreach (string instance2 in value.Split(';')) {
if (serverName == null) {
foreach(string instance3 in instance2.Split('\\')) {
if (serverName == null) {
serverName = instance3;
continue;
}
Debug.Assert(instanceName == null);
instanceName = instance3;
}
continue;
}
if (isClustered == null) {
Debug.Assert(String.Compare(_Cluster, 0, instance2, 0, _clusterLength, StringComparison.OrdinalIgnoreCase) == 0);
isClustered = instance2.Substring(_clusterLength);
continue;
}
Debug.Assert(version == null);
Debug.Assert(String.Compare(_Version, 0, instance2, 0, _versionLength, StringComparison.OrdinalIgnoreCase) == 0);
version = instance2.Substring(_versionLength);
}
string query = "ServerName='"+serverName+"'";
if (!ADP.IsEmpty(instanceName)) { // SQL BU DT 20006584: only append instanceName if present.
query += " AND InstanceName='"+instanceName+"'";
}
// SNI returns dupes - do not add them. SQL BU DT 290323
if (dataTable.Select(query).Length == 0) {
dataRow = dataTable.NewRow();
dataRow[0] = serverName;
dataRow[1] = instanceName;
dataRow[2] = isClustered;
dataRow[3] = version;
dataTable.Rows.Add(dataRow);
}
serverName = null;
instanceName = null;
isClustered = null;
version = null;
}
foreach(DataColumn column in dataTable.Columns) {
column.ReadOnly = true;
}
return dataTable;
}
}
}
// 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
- InstanceNameConverter.cs
- MinimizableAttributeTypeConverter.cs
- ValueProviderWrapper.cs
- odbcmetadatacollectionnames.cs
- MeasureItemEvent.cs
- NumericUpDownAcceleration.cs
- WebPartPersonalization.cs
- AnnotationDocumentPaginator.cs
- ExceptionUtil.cs
- BuilderPropertyEntry.cs
- ByteKeyFrameCollection.cs
- ReferentialConstraint.cs
- ObjectListCommandsPage.cs
- ExpressionValueEditor.cs
- listitem.cs
- ClientSideProviderDescription.cs
- ApplicationSecurityManager.cs
- TableRowCollection.cs
- HelpProvider.cs
- ListControlDesigner.cs
- PageParser.cs
- RowsCopiedEventArgs.cs
- SpellerHighlightLayer.cs
- errorpatternmatcher.cs
- IntPtr.cs
- SafeRightsManagementEnvironmentHandle.cs
- BmpBitmapEncoder.cs
- NumericUpDownAcceleration.cs
- TreeNodeMouseHoverEvent.cs
- IIS7WorkerRequest.cs
- X509Certificate2.cs
- TrailingSpaceComparer.cs
- DataSvcMapFile.cs
- PerspectiveCamera.cs
- HandleRef.cs
- ContentElement.cs
- IPAddress.cs
- DeviceSpecificChoice.cs
- UTF8Encoding.cs
- FontWeight.cs
- IriParsingElement.cs
- PrintDocument.cs
- TraceUtils.cs
- unsafenativemethodstextservices.cs
- WebBrowserBase.cs
- FormViewUpdateEventArgs.cs
- View.cs
- SmiRequestExecutor.cs
- StylusPointPropertyUnit.cs
- DesigntimeLicenseContextSerializer.cs
- KeyTime.cs
- sqlcontext.cs
- ImmutableObjectAttribute.cs
- RuleAction.cs
- SerializerProvider.cs
- GestureRecognizer.cs
- CapabilitiesUse.cs
- RoleService.cs
- WindowsHyperlink.cs
- PerspectiveCamera.cs
- XmlCharCheckingWriter.cs
- BinaryFormatter.cs
- XmlQualifiedName.cs
- PersistenceProviderDirectory.cs
- PrintDialogException.cs
- SchemaMerger.cs
- EntityAdapter.cs
- ChildrenQuery.cs
- XmlNodeReader.cs
- CryptoApi.cs
- MetafileHeader.cs
- BooleanStorage.cs
- WinFormsSpinner.cs
- OleDbPropertySetGuid.cs
- Visual3D.cs
- RSAOAEPKeyExchangeDeformatter.cs
- DateTimeConverter.cs
- UriSection.cs
- Label.cs
- OptimisticConcurrencyException.cs
- InvokeProviderWrapper.cs
- FormViewInsertEventArgs.cs
- ArrangedElement.cs
- HttpCacheParams.cs
- CngKeyCreationParameters.cs
- SingleKeyFrameCollection.cs
- GeometryCombineModeValidation.cs
- BaseTypeViewSchema.cs
- CalloutQueueItem.cs
- _TransmitFileOverlappedAsyncResult.cs
- WindowInteractionStateTracker.cs
- IdentityModelDictionary.cs
- WmpBitmapDecoder.cs
- CodeDirectionExpression.cs
- RotateTransform3D.cs
- Size3D.cs
- ThaiBuddhistCalendar.cs
- WindowInteropHelper.cs
- XmlObjectSerializer.cs
- PackageRelationship.cs