Skip to content

Instantly share code, notes, and snippets.

@SteveBate
Created March 30, 2015 13:22
Show Gist options
  • Select an option

  • Save SteveBate/90bd9b0aaf56edf85f65 to your computer and use it in GitHub Desktop.

Select an option

Save SteveBate/90bd9b0aaf56edf85f65 to your computer and use it in GitHub Desktop.
Example of connecting to Sql Server using async, await and tasks
async void Main()
{
var cnn = new SqlConnection("Data Source=ERPDBUAT;Initial Catalog=Enterprise_Misc; Integrated Security=true");
cnn.Open();
var cmd = new SqlCommand("SELECT * FROM ShopService.DivisionRules WHERE DivCode = 'MHL001'", cnn);
await cmd.ExecuteReaderAsync().ContinueWith(async rdr => {
await rdr.Result.ReadAsync().ContinueWith(ok => {
rdr.Result.GetBoolean(rdr.Result.GetOrdinal("IsMobileEnabled")).Dump();
rdr.Result.GetBoolean(rdr.Result.GetOrdinal("IsWebEnabled")).Dump();
rdr.Result.GetBoolean(rdr.Result.GetOrdinal("IsManualAddressEnabled")).Dump();
rdr.Result.GetBoolean(rdr.Result.GetOrdinal("ShouldValidateCompanyNameField")).Dump();
});
});
"hello world".Dump(); //linqpad
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment