Partager via


SqlConnectionFactory.CreateConnection, méthode

[Cette page concerne Entity Framework version 6. La dernière version est disponible sous le nom de package 'Entity Framework' NuGet. Pour plus d'informations sur Entity Framework, consultez msdn.com/data/ef.]

Crée une connexion pour SQL Server en fonction du nom de la base de données spécifiée ou d'une chaîne de connexion. Si la chaîne donnée contient un caractère '=', elle est traitée comme une chaîne de connexion complète, sinon, elle est traitée uniquement comme un nom de base de données.

Espace de noms :  System.Data.Entity.Infrastructure
Assembly :  EntityFramework (dans EntityFramework.dll)

Syntaxe

'Déclaration
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")> _
<SuppressMessageAttribute("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")> _
Public Function CreateConnection ( _
    nameOrConnectionString As String _
) As DbConnection
'Utilisation
Dim instance As SqlConnectionFactory 
Dim nameOrConnectionString As String 
Dim returnValue As DbConnection 

returnValue = instance.CreateConnection(nameOrConnectionString)
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SuppressMessageAttribute("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
public DbConnection CreateConnection(
    string nameOrConnectionString
)
[SuppressMessageAttribute(L"Microsoft.Reliability", L"CA2000:Dispose objects before losing scope")]
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1031:DoNotCatchGeneralExceptionTypes")]
public:
virtual DbConnection^ CreateConnection(
    String^ nameOrConnectionString
) sealed
[<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>]
[<SuppressMessageAttribute("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")>]
abstract CreateConnection : 
        nameOrConnectionString:string -> DbConnection 
[<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>]
[<SuppressMessageAttribute("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")>]
override CreateConnection : 
        nameOrConnectionString:string -> DbConnection
public final function CreateConnection(
    nameOrConnectionString : String
) : DbConnection

Paramètres

  • nameOrConnectionString
    Type : System.String
    Nom de base de données ou chaîne de connexion.

Valeur de retour

Type : System.Data.Common.DbConnection
DbConnection initialisé.

Implémentations

IDbConnectionFactory.CreateConnection(String)

Voir aussi

Référence

SqlConnectionFactory Classe

Espace de noms System.Data.Entity.Infrastructure