Code: Select all
.
.
.
public System.Data.SqlClient.SqlConnection getSQLConnection(String sServer, String sDatabase, String sUsername, String sPassword)
{
String conStr = "Server=" + sServer + ";Database=" + sDatabase + ";User Id=" + sUsername + ";Password=" + sPassword + ";Trusted_Connection=True; MultipleActiveResultSets=true;";
EventLog.WriteEntry(sSource, "Returning Connection String = " + conStr, EventLogEntryType.Information);
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(conStr);
EventLog.WriteEntry(sSource, "Returning Connection = " + conn.ConnectionString, EventLogEntryType.Information);
return conn;
}
.
.
.
//Later on in the code
_sqlConnection_ = getSQLConnection(Properties.Settings.Default.SQLServer, Properties.Settings.Default.SQLDatabase, Properties.Settings.Default.SQLUser, Properties.Settings.Default.SQLPassword);
_sqlConnection_.Open();
System.Data.SqlClient.SqlCommand comm = _sqlConnection_.CreateCommand();
comm.CommandText = Properties.Settings.Default.SQLQuery;
comm.CommandType = CommandType.Text;
Code: Select all
"Server=127.0.0.1;Database=stagingtable;User Id=*****;Password=*****;Trusted_Connection=True; MultipleActiveResultSets=true;"