connection string entity framework code example

Example 1: c# entity framework code first connection string

<connectionStrings>
    <add name="SchoolDB"
    connectionString="Data Source=Your Server Name ;Initial Catalog=SchoolDB;Integrated Security=false ; user id =sa ; password =*** "
    providerName="System.Data.SqlClient"/>
  </connectionStrings>

Example 2: entity framework connection string sql server

The Data Source key is used to find the machine on which the Sql Server instance runs.
You can have different strings for it but the most common used in a LAN environment is composed using the name of the server machine followed by an eventual instance name.

So, if your local PC is named GURUBEAST-PC and, at install time, you haven't specified any instance name, the connectionstring Data Source contains only the name of the machine GURUBEAST-PC. If you have an instance name then you should add that instance name to you Data Source key. GURUBEAST-PC\GURUSQL

This will guarantee to all the PC in the same LAN the possibility to have the same connectionstring also if the connection is made from the same PC where the SQL Server runs.

If the Data Source points at the local pc, you can use many shortcuts to represent the local PC:

(LOCAL)
localhost
.
\.
and eventually add the instance name to these shortcuts without repeating the PC name

Tags:

Sql Example