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 & I am using SQL server Express edition.
connection string I used for this "Initial Catalog=Employee;Server=serverName"
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;
}
Let me know if I missed something.