Export (0) Print
Expand All

EntityConnectionStringBuilder Class

Provides a simple way to create and manage the contents of connection strings used by the EntityClient.

System.Object
  System.Data.Common.DbConnectionStringBuilder
    System.Data.EntityClient.EntityConnectionStringBuilder

Namespace:  System.Data.EntityClient
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public sealed class EntityConnectionStringBuilder : DbConnectionStringBuilder

The EntityConnectionStringBuilder type exposes the following members.

  NameDescription
Public methodEntityConnectionStringBuilder()Initializes a new instance of the EntityConnectionStringBuilder class.
Public methodEntityConnectionStringBuilder(String)Initializes a new instance of the EntityConnectionStringBuilder class using the supplied connection string.
Top

  NameDescription
Public propertyBrowsableConnectionStringGets or sets a value that indicates whether the ConnectionString property is visible in Visual Studio designers. (Inherited from DbConnectionStringBuilder.)
Public propertyConnectionStringGets or sets the connection string associated with the DbConnectionStringBuilder. (Inherited from DbConnectionStringBuilder.)
Public propertyCountGets the current number of keys that are contained within the ConnectionString property. (Inherited from DbConnectionStringBuilder.)
Public propertyIsFixedSizeGets a value that indicates whether the EntityConnectionStringBuilder has a fixed size. (Overrides DbConnectionStringBuilder.IsFixedSize.)
Public propertyIsReadOnlyGets a value that indicates whether the DbConnectionStringBuilder is read-only. (Inherited from DbConnectionStringBuilder.)
Public propertyItemGets or sets the value associated with the specified key. In C#, this property is the indexer. (Overrides DbConnectionStringBuilder.Item.)
Public propertyKeysGets an ICollection that contains the keys in the EntityConnectionStringBuilder. (Overrides DbConnectionStringBuilder.Keys.)
Public propertyMetadataGets or sets the metadata locations in the connection string.
Public propertyNameGets or sets the name of a section as defined in a configuration file.
Public propertyProviderGets or sets the name of the underlying .NET Framework data provider in the connection string.
Public propertyProviderConnectionStringGets or sets the inner, provider-specific connection string.
Public propertyValuesGets an ICollection that contains the values in the DbConnectionStringBuilder. (Inherited from DbConnectionStringBuilder.)
Top

  NameDescription
Public methodAddAdds an entry with the specified key and value into the DbConnectionStringBuilder. (Inherited from DbConnectionStringBuilder.)
Public methodClearClears the contents of the EntityConnectionStringBuilder instance. (Overrides DbConnectionStringBuilder.Clear().)
Protected methodClearPropertyDescriptorsClears the collection of PropertyDescriptor objects on the associated DbConnectionStringBuilder. (Inherited from DbConnectionStringBuilder.)
Public methodContainsKeyDetermines whether the EntityConnectionStringBuilder contains a specific key. (Overrides DbConnectionStringBuilder.ContainsKey(String).)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodEquivalentToCompares the connection information in this DbConnectionStringBuilder object with the connection information in the supplied object. (Inherited from DbConnectionStringBuilder.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodRemoveRemoves the entry with the specified key from the EntityConnectionStringBuilder instance. (Overrides DbConnectionStringBuilder.Remove(String).)
Public methodShouldSerializeIndicates whether the specified key exists in this DbConnectionStringBuilder instance. (Inherited from DbConnectionStringBuilder.)
Public methodToStringReturns the connection string associated with this DbConnectionStringBuilder. (Inherited from DbConnectionStringBuilder.)
Public methodTryGetValueRetrieves a value corresponding to the supplied key from this EntityConnectionStringBuilder. (Overrides DbConnectionStringBuilder.TryGetValue(String, Object).)
Top

  NameDescription
Explicit interface implemetationPrivate methodICollection.CopyToCopies the elements of the ICollection to an Array, starting at a particular Array index. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate propertyICollection.IsSynchronizedGets a value indicating whether access to the ICollection is synchronized (thread safe). (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate propertyICollection.SyncRootGets an object that can be used to synchronize access to the ICollection. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetAttributesReturns a collection of custom attributes for this instance of a component. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetClassNameReturns the class name of this instance of a component. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetComponentNameReturns the name of this instance of a component. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetConverterReturns a type converter for this instance of a component. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetDefaultEventReturns the default event for this instance of a component. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetDefaultPropertyReturns the default property for this instance of a component. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetEditorReturns an editor of the specified type for this instance of a component. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetEvents()Returns the events for this instance of a component. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetEvents(Attribute[])Returns the events for this instance of a component using the specified attribute array as a filter. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetProperties()Returns the properties for this instance of a component. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetProperties(Attribute[])Returns the properties for this instance of a component using the attribute array as a filter. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodICustomTypeDescriptor.GetPropertyOwnerReturns an object that contains the property described by the specified property descriptor. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodIDictionary.AddAdds an element with the provided key and value to the IDictionary object. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodIDictionary.ContainsDetermines whether the IDictionary object contains an element with the specified key. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodIDictionary.GetEnumeratorReturns an IDictionaryEnumerator object for the IDictionary object. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate propertyIDictionary.ItemGets or sets the element with the specified key. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodIDictionary.RemoveRemoves the element with the specified key from the IDictionary object. (Inherited from DbConnectionStringBuilder.)
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns an enumerator that iterates through a collection. (Inherited from DbConnectionStringBuilder.)
Top

The connection string builder lets developers programmatically create syntactically correct connection strings, and parse and rebuild existing connection strings, by using properties and methods of the class. The connection string builder provides strongly typed properties corresponding to the known keyword/value pairs. Developers who must create connection strings as part of applications can use the EntityConnectionStringBuilder class to build and modify connection strings.

The EntityConnectionStringBuilder performs checks for valid keyword/value pairs, each of which is exposed as a EntityConnectionStringBuilder property value.

NoteNote

The connection string for the underlying data source is supplied by the ProviderConnectionString property. The supplied provider connection string is not checked for valid keyword/value pairs.

The following example demonstrates how to use the EntityConnectionStringBuilder in conjunction with a SqlConnectionStringBuilder.


// Specify the provider name, server and database. 
string providerName = "System.Data.SqlClient";
string serverName = ".";
string databaseName = "AdventureWorks";

// Initialize the connection string builder for the 
// underlying provider.
SqlConnectionStringBuilder sqlBuilder =
    new SqlConnectionStringBuilder();

// Set the properties for the data source.
sqlBuilder.DataSource = serverName;
sqlBuilder.InitialCatalog = databaseName;
sqlBuilder.IntegratedSecurity = true;

// Build the SqlConnection connection string. 
string providerString = sqlBuilder.ToString();

// Initialize the EntityConnectionStringBuilder.
EntityConnectionStringBuilder entityBuilder =
    new EntityConnectionStringBuilder();

//Set the provider name.
entityBuilder.Provider = providerName;

// Set the provider-specific connection string.
entityBuilder.ProviderConnectionString = providerString;

// Set the Metadata location.
entityBuilder.Metadata = @"res://*/AdventureWorksModel.csdl|
                            res://*/AdventureWorksModel.ssdl|
                            res://*/AdventureWorksModel.msl";
Console.WriteLine(entityBuilder.ToString());

using (EntityConnection conn =
    new EntityConnection(entityBuilder.ToString()))
{
    conn.Open();
    Console.WriteLine("Just testing the connection.");
    conn.Close();
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft