using (EntityConnection connection = new EntityConnection("name=NorthwindEntities")) { connection.Open(); // perform database operations }
string connectionString = "metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider connection string='Data Source=server_name;Initial Catalog=Northwind;Integrated Security=True'"; using (EntityConnection connection = new EntityConnection(connectionString)) { connection.Open(); // perform database operations }In this example, the connection string is constructed using metadata information and a SQL Server provider. The EntityConnection object is then created using this connection string and the connection is opened using the Open() method. The package library for the System.Data.EntityClient namespace is System.Data.EntityClient.