This documentation is archived and is not being maintained.

EntityConnectionStringBuilder Class

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

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

'Declaration
Public NotInheritable Class EntityConnectionStringBuilder _
	Inherits DbConnectionStringBuilder
'Usage
Dim instance As EntityConnectionStringBuilder

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. 
Dim providerName As String = "System.Data.SqlClient" 
Dim serverName As String = "." 
Dim databaseName As String = "AdventureWorks" 

' Initialize the connection string builder for the 
' underlying provider. 
Dim sqlBuilder As New SqlConnectionStringBuilder

' Set the properties for the data source.
sqlBuilder.DataSource = serverName
sqlBuilder.InitialCatalog = databaseName
sqlBuilder.IntegratedSecurity = True 

' Build the SqlConnection connection string. 
Dim providerString As String = sqlBuilder.ToString

' Initialize the EntityConnectionStringBuilder. 
Dim entityBuilder As New EntityConnectionStringBuilder

'Set the provider name.
entityBuilder.Provider = providerName
' Set the provider-specific connection string.
entityBuilder.ProviderConnectionString = providerString
' Set the Metadata location to the current directory.
entityBuilder.Metadata = "res://*/AdventureWorksModel.csdl|" & _
                            "res://*/AdventureWorksModel.ssdl|" & _
                            "res://*/AdventureWorksModel.msl"

Console.WriteLine(entityBuilder.ToString)

Using conn As EntityConnection = New EntityConnection(entityBuilder.ToString)
    conn.Open()
    Console.WriteLine("Just testing the connection.")
    conn.Close()
End Using

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

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5 SP1
Show: