« Migrating on premise SQL Server Database to off premise SQL Azure | Main | Infosys at Microsoft's CRM 360 Virtual Summit »

Entity Framework handshake with SQL Azure

Entity Framework shipped with .NET Framework 4 helps in building data access layer to interact with SQL Server or for that matter any data store. Enterprises that have invested in building web applications with Entity Framework, SQL Server as a database and now needing to move to SQL Azure database will need to see how their existing applications will seamlessly work with SQL Azure as a database.
I am sure many clients would consider this as one of the key consideration while planning application migration to off premise fully or partly.

Entity Framework can be used to connect to SQL Azure database in the same way as SQL Server database and it is seamless.
If you have developed any existing application with Entity Framework and SQL Server, it can be made to work with database on SQL Azure with little changes as outline here
Change the following highlighted items in the connecting string to connect to SQL Azure database

Connection String for SQL Server


 <add name="NewGenBankEntities"          connectionString="metadata=res://*/NewGenBankDataModel.csdl|res://*/NewGenBankDataModel.ssdl|res://*/NewGenBankDataModel.msl;
provider=System.Data.SqlClient;provider connection string=&quot;
         Data Source=.\sqlexpress;
         Initial Catalog=NewGenBank;
         Integrated Security=True;
         MultipleActiveResultSets=True&quot;"
         providerName="System.Data.EntityClient"/>

Connection String for SQL Azure


<connectionStrings>
    <add name="NewGenBankEntities"          connectionString="metadata=res://*/NewGenBankDataModel.csdl|res://*/NewGenBankDataModel.ssdl|res://*/NewGenBankDataModel.msl;
provider=System.Data.SqlClient;provider connection string=&quot;
         Data Source=xxx.database.windows.net;
         Initial Catalog=NewGenBank;
         Persist Security Info=True;
         User ID=sqluser;
         Password=xxx;

         MultipleActiveResultSets=True&quot;"
         providerName="System.Data.EntityClient" />
</connectionStrings>

Note that for SQL Azure, there is no Integrated Security and one needs to use SQL Server authentication. Database password can be hashed instead of having it naked in config file.
Once this is done, your application should work seamlessly with SQL Azure as a database.

TrackBack

TrackBack URL for this entry:
http://www.infosysblogs.com/apps/mt-tb.cgi/4610

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Please key in the two words you see in the box to validate your identity as an authentic user and reduce spam.

Subscribe to this blog's feed

Follow us on

Blogger Profiles

Infosys on Twitter