I have a method with a signature like this:
internal async static Task<string> Get()
{
var SqlCon = await InitializeConnection();
return "Foo";
}
I call this method like this:
var x = Get().Result;
Description of other method
internal async static Task<SqlConnection> InitializeConnection()
{
SqlConnection sc;
sc = new SqlConnection();
sc.ConnectionString = @"Data Source=.\MSSQL;Initial Catalog=MyDB;Integrated Security=True;Async=True";
await sc.OpenAsync();//on this line the program long waits and doesn't connect
return sc;
}
I checked with different correct lines of connection without use of asynchrony and everything worked. How to fix it ? Thank you.