C# console application Invalid Operation Exception
The correct way doing that should be something like:
static void Main(string[] args) {
string connectionString = "Data Source=H....;
Initial Catalog=LANDesk;User ID=Mainstc; Password=xxxxxxxx";
// removed Persist Security Info=True;
using(SqlConnection con = new SqlConnection(connectionString))
{
if (con.State==ConnectionState.Closed)
{
con.Open();
}
}
}
Using Using Statement
it will automatically dispose your SQL connection.
Check this also: Best Practices for Using ADO.NET on MSDN
Other things to do: Use SQL Management Studio and try to use your sql authentication login credential from your connection string and if you have successfully connected to your database using that account the above code should work for you.
Best Regards
The code should read
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
...
}