EntityConnectionStringBuilder Конструкторы

Определение

Инициализация нового экземпляра класса EntityConnectionStringBuilder.Initializes a new instance of the EntityConnectionStringBuilder class.

Перегрузки

EntityConnectionStringBuilder()

Инициализация нового экземпляра класса EntityConnectionStringBuilder.Initializes a new instance of the EntityConnectionStringBuilder class.

EntityConnectionStringBuilder(String)

Инициализирует новый экземпляр класса EntityConnectionStringBuilder с помощью указанной строки соединения.Initializes a new instance of the EntityConnectionStringBuilder class using the supplied connection string.

EntityConnectionStringBuilder()

Инициализация нового экземпляра класса EntityConnectionStringBuilder.Initializes a new instance of the EntityConnectionStringBuilder class.

public:
 EntityConnectionStringBuilder();
public EntityConnectionStringBuilder ();
Public Sub New ()

Примеры

В следующем примере показано использование класса EntityConnectionStringBuilder в сочетании с классом SqlConnectionStringBuilder.The following example demonstrates how to use the EntityConnectionStringBuilder in conjunction with a SqlConnectionStringBuilder. Код задает свойства SqlConnectionStringBuilder для создания SqlConnection строки подключения, которая предоставляет часть строки подключения базового поставщика.The code sets properties of a SqlConnectionStringBuilder to create a SqlConnection connection string that supplies part of the underlying provider connection string. Обратите внимание, что имя поставщика нельзя задать с помощью SqlConnectionStringBuilder, так как оно недопустимо SqlConnection синтаксис строки соединения.Note that the Provider name cannot be set using the SqlConnectionStringBuilder because it is not valid SqlConnection connection string syntax. Код создает EntityConnection строку подключения, настроив свойства EntityConnectionStringBuilder.The code creates the EntityConnection connection string by setting EntityConnectionStringBuilder properties.


// 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();
}
' 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

Дополнительно

EntityConnectionStringBuilder(String)

Инициализирует новый экземпляр класса EntityConnectionStringBuilder с помощью указанной строки соединения.Initializes a new instance of the EntityConnectionStringBuilder class using the supplied connection string.

public:
 EntityConnectionStringBuilder(System::String ^ connectionString);
public EntityConnectionStringBuilder (string connectionString);
new System.Data.EntityClient.EntityConnectionStringBuilder : string -> System.Data.EntityClient.EntityConnectionStringBuilder
Public Sub New (connectionString As String)

Параметры

connectionString
String

Строка подключения для конкретного поставщика к базовому источнику данных.A provider-specific connection string to the underlying data source.

Примеры

В следующем примере показано использование класса EntityConnectionStringBuilder в сочетании с классом SqlConnectionStringBuilder.The following example demonstrates how to use the EntityConnectionStringBuilder in conjunction with a SqlConnectionStringBuilder. Код задает свойства SqlConnectionStringBuilder для создания SqlConnection строки подключения, которая предоставляет часть строки подключения базового поставщика.The code sets properties of a SqlConnectionStringBuilder to create a SqlConnection connection string that supplies part of the underlying provider connection string. Обратите внимание, что имя поставщика нельзя задать с помощью SqlConnectionStringBuilder, так как оно недопустимо SqlConnection синтаксис строки соединения.Note that the Provider name cannot be set using the SqlConnectionStringBuilder because it is not valid SqlConnection connection string syntax. Код создает EntityConnection строку подключения, настроив свойства EntityConnectionStringBuilder.The code creates the EntityConnection connection string by setting EntityConnectionStringBuilder properties. Он не использует перегрузку connectionString.It does not use the connectionString overload.


// 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();
}
' 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

Комментарии

Предоставленный connectionString не проверяется на допустимость пар "ключевое слово-значение".The supplied connectionString is not checked for valid keyword/value pairs. Допустимый синтаксис ключевых слов и значений см. в ConnectionString.For valid keyword/value syntax, see ConnectionString.

В параметре connectionString необходимо указать имя инвариантного поставщика.The invariant Provider name must be specified in the connectionString parameter. Поддерживаются следующие поставщики:Supported providers include the following:

  • System.Data.Odbc

  • System.Data.OleDb

  • System.Data.OracleClient

  • System.Data.SqlClient

  • Microsoft.SqlServerCe.Client

Дополнительно

Применяется к