SqlConnectionFactory.CreateConnection 方法
[本页针对的是实体框架版本 6。最新版本以“实体框架”NuGet 包的形式提供。有关实体框架的更多信息,请参见 msdn.com/data/ef。]
基于给定的数据库名称或连接字符串为 SQL Server 创建连接。 如果给定的字符串包含“=”字符,则将其视为一个完整的连接字符串,否则仅将其视为数据库名称。
命名空间: System.Data.Entity.Infrastructure
程序集: EntityFramework(在 EntityFramework.dll 中)
语法
声明
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")> _
<SuppressMessageAttribute("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")> _
Public Function CreateConnection ( _
nameOrConnectionString As String _
) As DbConnection
用法
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
参数
- nameOrConnectionString
类型:System.String
数据库名称或连接字符串。
返回值
类型:System.Data.Common.DbConnection
已初始化的 DbConnection。
Implements
IDbConnectionFactory.CreateConnection(String)