示例#1
0
        private static void CreateLog(string funcName, IDictionary sqlParamMap, ref String connString, ref String query, ref Exception exc)
        {
            var str = new StringBuilder("DB-Err, Func Name: " + funcName + " \r\n");

            str.AppendLine("Connection Str:" + connString);
            str.AppendLine("Query:" + query);
            if (sqlParamMap != null)
            {
                str.AppendLine("Key - Value <----- Parameters");
                foreach (DictionaryEntry de in sqlParamMap)
                {
                    str.AppendLine((de.Key == null ? string.Empty : de.Key.ToString()) + "-" + (de.Value == null ? string.Empty : de.Value.ToString()));
                }
            }
            str.AppendLine("--------------------------------------");
            str.AppendLine("Exception Msg: " + exc.Message);
            str.AppendLine("Exception Source: " + exc.Source);
            //str.AppendLine("Exception Stack Trace: " + exc.StackTrace);
            //ErrLogger.Log(str.ToString());
            WebUtility.ElmahLog(ref exc, str.ToString());
        }
示例#2
0
        /// <summary>
        /// private database access helper method that inserts, updates and deletes data to CMS tables
        /// </summary>
        public static void BatchModifyDatabase(List <string> sqls, string connString, string command)
        {
            int            rowCount  = -1;
            IDbDataAdapter dbadapter = null;
            IDbConnection  dbcon     = null;
            IDbCommand     dbcmd     = null;

            try
            {
                dbcon = new SqlConnection(ConfigurationManager.ConnectionStrings[connString].ToString());
                dbcon.Open();
                dbcmd = dbcon.CreateCommand();

                for (int i = 0; i < sqls.Count; i++)
                {
                    dbcmd.CommandText = sqls[i];
                    dbadapter         = new SqlDataAdapter();
                    if (command.Equals("InsertCommand"))
                    {
                        dbadapter.InsertCommand = dbcmd;
                        rowCount = Convert.ToInt32(dbcmd.ExecuteScalar());
                    }
                    else if (command.Equals("UpdateCommand"))
                    {
                        dbadapter.UpdateCommand = dbcmd;
                        rowCount = dbcmd.ExecuteNonQuery();
                    }
                    else if (command.Equals("DeleteCommand"))
                    {
                        dbadapter.DeleteCommand = dbcmd;
                        rowCount = dbcmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception exc)
            {
                var str = new StringBuilder("DB-Err, Func Name: BatchModifyDatabase \r\n");
                str.AppendLine("Connection Str:" + connString);
                if (sqls != null)
                {
                    str.AppendLine("Total sqls:" + sqls.Count);
                    for (int i = 0; i < sqls.Count; i++)
                    {
                        str.AppendLine(sqls[i]);
                    }
                }
                WebUtility.ElmahLog(ref exc, str.ToString());
            }
            finally
            {
                if (dbcmd != null)
                {
                    dbcmd.Dispose();
                }
                dbcmd = null;
                if (dbcon != null)
                {
                    dbcon.Close();
                }
                dbcon = null;
            }
        }