Q:

Connect to database using sql server authentication programatically

How can I connect to database using sql server authentication programmatically in c# winforms? I mean i created a login named loginTesting with a loginTesting as user in sql server 2012. I want to access that login in c# by accepting user inputs from textbox. Thanks.

A:

You can use the class SqlConnectionStringBuilder to construct the connection string that you will need for a SqlConnection object:
SqlConnectionStringBuilder scsBuilder = new SqlConnectionStringBuilder();
scsBuilder.UserID = "username";
scsBuilder.Password = "password";
scsBuilder.DataSource = "servername or ip address";
scsBuilder.InitialCatalog = "databasename";
scsBuilder.IntegratedSecurity = false;

using (SqlConnection sqlCon = new SqlConnection(scsBuilder.ConnectionString))
{
  // perform your SQL tasks
}

Further reading here:
SqlConnectionStringBuilder Class
SqlConnection Class

A:

Expanding on Answer 1, if you'd like to test your usernames/passwords based on user input you could use the SqlConnectionStringBuilder object as shown in this example:
SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder();
connectionString.ConnectionString = @"data source=.;initial catalog=master;";
connectionString.UserID = "username";
connectionString.Password = "password";

using (var sqlConnection = new SqlConnection(connectionString.ConnectionString))
{

}

