title: Error : Login failed for user 'domain\username' using SqlCredential object
body: <p>I am using below mentioned code when I tried to connect with SQL server. I am geeting  Login failed for user 'domain\username'. I have checked that the user having sysadmin permission in SQL Server &amp; I am using SQL server Express edition. </p>
  
  <p>connection string I used for this "Initial Catalog=Employee;Server=serverName"</p>
  
  <pre><code> public static bool connectSqlClient(string connecton)
       {
           bool isConnect = false;
           try
           {
               string username = @"domain\username";
               string initString = "abcpassowrd";
               // Instantiate the secure string.
               SecureString testString = new SecureString();
  
               // Use the AppendChar method to add each char value to the secure string. 
               foreach (char ch in initString)
                   testString.AppendChar(ch);
  
               testString.MakeReadOnly();
               SqlCredential cred = new SqlCredential(username, testString);
               SqlConnection conn = new SqlConnection(connecton, cred);
               conn.Open();
               isConnect = true;
           }
           catch (Exception)
           {
               throw;
           }
  
           return isConnect;
       }
  </code></pre>
  
  <p>Let me know if I missed something. </p>