Пример #1
0
        private SqlConnection DataConnection(DBConnection dataConnectionIndicator)
        {
            SqlConnection cnnRtn = null;

            try
            {
                switch (dataConnectionIndicator)
                {
                case DBConnection.SqlMainNew:
                    cnnRtn = SqlMainNewDBConnection;
                    break;

                case DBConnection.SqlProd01:
                    cnnRtn = SqlProd01DBConnection;
                    break;

                case DBConnection.NameSys:
                    cnnRtn = SqlNameSysDBConnection;
                    break;
                }
            }
            catch (Exception ex)
            {
                DAL.ImportControl.ImportControlRepository icr = new ImportControlRepository();
                icr.writeSyncLog(1, Convert.ToInt16(ConfigurationManager.AppSettings["ServiceID"]), 1, "Error getting db connection", ex.Message);
                //ApplicationLogging.WriteCriticalExceptionMessage(ex, "Error getting database connection", "DBConnection");
                throw;
            }
            return(cnnRtn);
        }
Пример #2
0
        public object ExecuteScalar(string procedureName, DBConnection dbConnection, System.Collections.Specialized.NameValueCollection args)
        {
            object rtn = null;

            using (SqlCommand cmd = new SqlCommand(procedureName, DataConnection(dbConnection)))
            {
                try
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    foreach (string key in args)
                    {
                        cmd.Parameters.AddWithValue(key, args[key]);
                    }
                    cmd.CommandTimeout = 0;
                    rtn = cmd.ExecuteScalar();
                }
                catch (Exception ex)
                {
                    string err = "Error ExecuteScalar error: Proc. = " + procedureName + " Args = " + args.Keys;
                    DAL.ImportControl.ImportControlRepository icr = new ImportControlRepository();
                    icr.writeSyncLog(1, Convert.ToInt16(ConfigurationManager.AppSettings["ServiceID"]), 1, err, ex.Message);
                    //wtf.writeSyncLog(9, "ExecuteScalar error: Proc. = " + procedureName + " Args = " + args.Keys, ex.Message);
                    //wlf.WriteToFile("WSP Sync Service ExecuteScalar error: Proc. = " + procedureName + " Args = " + args.Keys + " Log: {0} - Sql error: " + ex);
                    throw;
                }
                finally
                {
                    if ((cmd != null) && (cmd.Connection != null) && (cmd.Connection.State != ConnectionState.Closed))
                    {
                        cmd.Connection.Close();
                    }
                }
            }
            return(rtn);
        }