Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / DataAccess / DataConnectionHelper.cs / 1 / DataConnectionHelper.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Web.UI; [assembly:WebResource("add_permissions_for_users.gif", "image/gif")] [assembly:WebResource("properties_security_tab_w_user.gif", "image/gif")] [assembly:WebResource("properties_security_tab.gif", "image/gif")] namespace System.Web.DataAccess { using System; using System.Web; using System.Globalization; using System.Collections; using System.Collections.Specialized; using System.Data; using System.Data.OleDb; using System.IO; using System.Threading; using System.Configuration; using System.Web.Util; using System.Security.Permissions; using System.Web.Hosting; using System.Security.Principal; using System.Web.UI; using System.Web.Handlers; using System.Web.Configuration; using System.Diagnostics; using System.Text; ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// internal enum DataConnectionErrorEnum { CanNotCreateDataDir, CanNotWriteToDataDir, CanNotWriteToDBFile } internal static class DataConnectionHelper { internal static string GetCurrentName() { string userName = "NETWORK SERVICE"; string domainName = "NT AUTHORITY"; IntPtr pSid = IntPtr.Zero; try { if( UnsafeNativeMethods.ConvertStringSidToSid( "S-1-5-20", out pSid ) != 0 && pSid != IntPtr.Zero ) { int userNameLen = 256; int domainNameLen = 256; int sidNameUse = 0; StringBuilder bufUserName = new StringBuilder( userNameLen ); StringBuilder bufDomainName = new StringBuilder( domainNameLen ); if( 0 != UnsafeNativeMethods.LookupAccountSid( null, pSid, bufUserName, ref userNameLen, bufDomainName, ref domainNameLen, ref sidNameUse ) ) { userName = bufUserName.ToString(); domainName = bufDomainName.ToString(); } } WindowsIdentity id = WindowsIdentity.GetCurrent(); if( id != null && id.Name != null ) { if ( string.Compare( id.Name, domainName + @"\" + userName, StringComparison.OrdinalIgnoreCase ) == 0 ) { return userName; } return id.Name; } } catch {} finally { if( pSid != IntPtr.Zero ) { UnsafeNativeMethods.LocalFree( pSid ); } } return String.Empty; } } internal class DataConnectionErrorFormatter : ErrorFormatter { protected static NameValueCollection s_errMessages = new NameValueCollection(); protected static object s_Lock = new object (); protected string _UserName; protected DataConnectionErrorEnum _Error; protected override string ErrorTitle { get { return null; } } protected override string Description { get { return null; } } protected override string MiscSectionTitle { get { return SR.GetString ( SR.DataAccessError_MiscSectionTitle ); } } protected override string MiscSectionContent { get { string url; int currentNumber = 1; string resourceString = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_1); string miscContent = "\n
- " + resourceString + "
\n"; switch (_Error) { case DataConnectionErrorEnum.CanNotCreateDataDir: resourceString = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_2_CanNotCreateDataDir); miscContent += "- " + resourceString + "
\n"; resourceString = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_2); miscContent += "- " + resourceString + "
\n"; break; case DataConnectionErrorEnum.CanNotWriteToDataDir: resourceString = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_2); miscContent += "- " + resourceString + "
\n"; break; case DataConnectionErrorEnum.CanNotWriteToDBFile: resourceString = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_2_CanNotWriteToDBFile_a); miscContent += "- " + resourceString + "
\n"; resourceString = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_2_CanNotWriteToDBFile_b); miscContent += "- " + resourceString + "
\n"; break; } resourceString = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_3); miscContent += "- " + resourceString + "
\n"; url = AssemblyResourceLoader.GetWebResourceUrl(typeof(Page), "properties_security_tab.gif", true); miscContent += "
"; resourceString = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_ClickAdd); miscContent += "- " + resourceString + "
\n"; url = AssemblyResourceLoader.GetWebResourceUrl(typeof(Page), "add_permissions_for_users.gif", true); miscContent += "
"; string four; if (!String.IsNullOrEmpty(_UserName)) four = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_4, _UserName); else four = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_4_2); miscContent += "- " + four + "
\n"; resourceString = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_ClickOK); miscContent += "- " + resourceString + "
\n"; resourceString = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_5); miscContent += "- " + resourceString + "
\n"; url = AssemblyResourceLoader.GetWebResourceUrl(typeof(Page), "properties_security_tab_w_user.gif", true); miscContent += "
"; resourceString = GetResourceStringAndSetAdaptiveNumberedText(ref currentNumber, SR.DataAccessError_MiscSection_ClickOK); miscContent += "- " + resourceString + "
\n"; return miscContent; } } protected override string ColoredSquareTitle { get { return null; } } protected override string ColoredSquareContent { get { return null; } } protected override bool ShowSourceFileInfo { get { return false; } } private string GetResourceStringAndSetAdaptiveNumberedText(ref int currentNumber, string resourceId) { string resourceString = SR.GetString(resourceId); SetAdaptiveNumberedText(ref currentNumber, resourceString); return resourceString; } private string GetResourceStringAndSetAdaptiveNumberedText(ref int currentNumber, string resourceId, string parameter1) { string resourceString = SR.GetString(resourceId, parameter1); SetAdaptiveNumberedText(ref currentNumber, resourceString); return resourceString; } private void SetAdaptiveNumberedText(ref int currentNumber, string resourceString) { string adaptiveText = currentNumber.ToString(CultureInfo.InvariantCulture) + " " + resourceString; AdaptiveMiscContent.Add(adaptiveText); currentNumber += 1; } } internal sealed class SqlExpressConnectionErrorFormatter : DataConnectionErrorFormatter { internal SqlExpressConnectionErrorFormatter(DataConnectionErrorEnum error) { _UserName = (HttpRuntime.HasUnmanagedPermission() ? DataConnectionHelper.GetCurrentName() : String.Empty); _Error = error; } internal SqlExpressConnectionErrorFormatter(string userName, DataConnectionErrorEnum error) { _UserName = userName; _Error = error; } protected override string ErrorTitle { get { string resourceKey = null; switch ( _Error ) { case DataConnectionErrorEnum.CanNotCreateDataDir: resourceKey = SR.DataAccessError_CanNotCreateDataDir_Title; break; case DataConnectionErrorEnum.CanNotWriteToDataDir: resourceKey = SR.SqlExpressError_CanNotWriteToDataDir_Title; break; case DataConnectionErrorEnum.CanNotWriteToDBFile: resourceKey = SR.SqlExpressError_CanNotWriteToDbfFile_Title; break; } return SR.GetString (resourceKey); } } protected override string Description { get { string resourceKey1 = null; string resourceKey2 = null; switch (_Error) { case DataConnectionErrorEnum.CanNotCreateDataDir: resourceKey1 = SR.DataAccessError_CanNotCreateDataDir_Description; resourceKey2 = SR.DataAccessError_CanNotCreateDataDir_Description_2; break; case DataConnectionErrorEnum.CanNotWriteToDataDir: resourceKey1 = SR.SqlExpressError_CanNotWriteToDataDir_Description; resourceKey2 = SR.SqlExpressError_CanNotWriteToDataDir_Description_2; break; case DataConnectionErrorEnum.CanNotWriteToDBFile: resourceKey1 = SR.SqlExpressError_CanNotWriteToDbfFile_Description; resourceKey2 = SR.SqlExpressError_CanNotWriteToDbfFile_Description_2; break; } string desc; if (!String.IsNullOrEmpty(_UserName)) desc = SR.GetString (resourceKey1, _UserName); else desc = SR.GetString (resourceKey2); desc += " " + SR.GetString (SR.SqlExpressError_Description_1); return desc; } } } internal sealed class SqlExpressDBFileAutoCreationErrorFormatter : UnhandledErrorFormatter { static string s_errMessage = null; static object s_Lock = new object(); internal SqlExpressDBFileAutoCreationErrorFormatter( Exception exception ) : base( exception ) { } protected override string MiscSectionTitle { get { return SR.GetString( SR.SqlExpress_MDF_File_Auto_Creation_MiscSectionTitle ); } } protected override string MiscSectionContent { get { return CustomErrorMessage; } } internal static string CustomErrorMessage { get { if( s_errMessage == null ) { lock( s_Lock ) { if( s_errMessage == null ) { string resourceString; resourceString = SR.GetString( SR.SqlExpress_MDF_File_Auto_Creation ); s_errMessage += "" + resourceString + "
\n"; s_errMessage += "\n"; resourceString = SR.GetString( SR.SqlExpress_MDF_File_Auto_Creation_1 ); s_errMessage += "
\n"; } } } return s_errMessage; } } } }- " + resourceString + "
\n"; resourceString = SR.GetString( SR.SqlExpress_MDF_File_Auto_Creation_2 ); s_errMessage += "- " + resourceString + "
\n"; resourceString = SR.GetString( SR.SqlExpress_MDF_File_Auto_Creation_3 ); s_errMessage += "- " + resourceString + "
\n"; resourceString = SR.GetString( SR.SqlExpress_MDF_File_Auto_Creation_4 ); s_errMessage += "- " + resourceString + "
\n"; s_errMessage += "
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataGridLength.cs
- RepeaterCommandEventArgs.cs
- DateTimeOffset.cs
- Imaging.cs
- ReadWriteControlDesigner.cs
- SqlPersonalizationProvider.cs
- ImageSource.cs
- BitmapEffectInput.cs
- ObjectItemCollection.cs
- MSAANativeProvider.cs
- WorkflowServiceNamespace.cs
- FormViewInsertEventArgs.cs
- Soap12ServerProtocol.cs
- _BufferOffsetSize.cs
- MasterPageBuildProvider.cs
- _SSPIWrapper.cs
- CriticalExceptions.cs
- CodeIdentifier.cs
- RoleManagerSection.cs
- IApplicationTrustManager.cs
- PolicyValidationException.cs
- BindingMemberInfo.cs
- MD5CryptoServiceProvider.cs
- BinaryCommonClasses.cs
- SessionStateModule.cs
- PauseStoryboard.cs
- GenerateScriptTypeAttribute.cs
- AutomationElementIdentifiers.cs
- ZoneIdentityPermission.cs
- ViewDesigner.cs
- UserMapPath.cs
- _SSPIWrapper.cs
- _AutoWebProxyScriptEngine.cs
- ScanQueryOperator.cs
- _SafeNetHandles.cs
- XmlILOptimizerVisitor.cs
- TextEditorLists.cs
- ColorPalette.cs
- ListBindableAttribute.cs
- Span.cs
- CultureTable.cs
- StructuralObject.cs
- ExtensionQuery.cs
- Schema.cs
- KnownTypeDataContractResolver.cs
- DescendantOverDescendantQuery.cs
- JsonReader.cs
- Rectangle.cs
- SafeRegistryHandle.cs
- EventProviderTraceListener.cs
- SchemaElementDecl.cs
- WebServiceFaultDesigner.cs
- NegationPusher.cs
- securestring.cs
- EncryptedReference.cs
- PackageStore.cs
- DataContractSerializerOperationBehavior.cs
- ProgressBar.cs
- TemplatedAdorner.cs
- XmlWriterTraceListener.cs
- SystemWebExtensionsSectionGroup.cs
- TraceContext.cs
- DrawingBrush.cs
- BamlCollectionHolder.cs
- CodeLabeledStatement.cs
- BigInt.cs
- Avt.cs
- WorkflowDesigner.cs
- ConnectionStringSettings.cs
- ExternalException.cs
- _TLSstream.cs
- BaseCAMarshaler.cs
- CompiledXpathExpr.cs
- CacheVirtualItemsEvent.cs
- LocationSectionRecord.cs
- HtmlHistory.cs
- URIFormatException.cs
- DataObjectSettingDataEventArgs.cs
- KeyInterop.cs
- SchemaDeclBase.cs
- ObjectPropertyMapping.cs
- CodeVariableReferenceExpression.cs
- WebDescriptionAttribute.cs
- TemplateKey.cs
- BaseTemplateBuildProvider.cs
- Dynamic.cs
- DispatcherExceptionEventArgs.cs
- FocusWithinProperty.cs
- XsltLibrary.cs
- ImageFormatConverter.cs
- FileSystemWatcher.cs
- TextBoxAutoCompleteSourceConverter.cs
- CellParagraph.cs
- SeparatorAutomationPeer.cs
- SelectionRangeConverter.cs
- RegionData.cs
- GenericRootAutomationPeer.cs
- GradientSpreadMethodValidation.cs
- OutputCacheSettingsSection.cs
- DataSourceSelectArguments.cs