xpo-8383-examples-how-to-connect-to-sql-azure.md
With XPO, connecting to SQL Azure is similar to connecting to SQL Server. Because SQL Azure Database represents a cloud-based database service built on Microsoft SQL Server technologies, the connection requires the same connection provider, MSSqlConnectionProvider, which was extended with support for SQL Azure. So, to connect to a SQL Azure database, you can use the same techniques described in the How to: Connect to a SQL Server topic. The only difference involves specifying a cloud-based SQL server instance as a data source.
As with SQL Server, you can manually specify a SQL Azure connection string. To indicate that the MSSqlConnectionProvider needs to be used, add the “Initial Catalog” entry to the connection string, as shown below.
XpoDefault.Session.ConnectionString = String.Format(
"data source=tcp:{0}.database.windows.net;initial catalog={1};user id={2};password={3};",
serverName, databaseName, userName, password);
XpoDefault.Session.ConnectionString = String.Format( _
"data source=tcp:{0}.database.windows.net;initial catalog={1};user id={2};password={3};" _
, serverName, databaseName, userName, password)
As with SQL Server, you can use the MSSqlConnectionProvider.GetConnectionString overloaded function to create the default Data Access Layer (DAL).
string sqlConn =
MSSqlConnectionProvider.GetConnectionString(@"tcp:MyServer.database.windows.net", "MyDatabase");
XpoDefault.DataLayer = XpoDefault.GetDataLayer(sqlConn, AutoCreateOption.DatabaseAndSchema);
Dim sqlConn = _
MSSqlConnectionProvider.GetConnectionString("tcp:MyServer.database.windows.net", "MyDatabase")
XpoDefault.DataLayer = XpoDefault.GetDataLayer(sqlConn, AutoCreateOption.DatabaseAndSchema)
See Also
How To: Connect XPO to a Database Server (ASP.NET WebForms)
How to: Connect XPO to a Database Other than Microsoft SQL or Microsoft Access