Пример #1
0
 //返回SqlDataReader对象方法
 public static SqlDataReader ExecuteReader(string sql, CommandType cmdType, params SqlParameter[] pms)
 {
     DecryptAndEncryptionHelper dec = new DecryptAndEncryptionHelper();
     string d = dec.Decrypto(ConnStr);
     SqlConnection conn = new SqlConnection(dec.Decrypto(ConnStr));
     using (SqlCommand cmd = new SqlCommand(sql, conn))
     {
         cmd.CommandType = cmdType;
         if (pms != null)
         {
             cmd.Parameters.AddRange(pms);
         }
         try
         {
             conn.Open();
             return cmd.ExecuteReader(CommandBehavior.CloseConnection);
         }
         catch (Exception)
         {
             conn.Close();
             conn.Dispose();
             throw;
         }
     }
 }
Пример #2
0
 //封装一个返回DataTable的方法
 public static DataTable ExecuteDataTable(string sql, CommandType cmdType, params SqlParameter[] pms)
 {
     DecryptAndEncryptionHelper dec = new DecryptAndEncryptionHelper();
     DataTable dt = new DataTable();
     var a = dec.Decrypto(ConnStr);
     using (SqlDataAdapter adapter = new SqlDataAdapter(sql,ConnStr))
     {
         adapter.SelectCommand.CommandType = cmdType;
         if (pms != null)
         {
             adapter.SelectCommand.Parameters.AddRange(pms);
         }
         adapter.Fill(dt);
     }
     return dt;
 }
Пример #3
0
        //Server=.;database=xgxDB;uid=sa;pwd=123456
        //执行增删改
        public static int ExecuteNonQury(string sql, CommandType cmdType, params SqlParameter[] pms)
        {
            DecryptAndEncryptionHelper dec = new DecryptAndEncryptionHelper();

            using (SqlConnection conn = new SqlConnection(dec.Decrypto(ConnStr)))
            {
                using (SqlCommand cmd = new SqlCommand(sql, conn))
                {
                    cmd.CommandType = cmdType;
                    if (pms != null)
                    {
                        cmd.Parameters.AddRange(pms);
                    }
                    conn.Open();
                    return cmd.ExecuteNonQuery();
                }
            }
        }
Пример #4
0
        private static void ConfigLogConnection()
        {
            if (String.IsNullOrEmpty(ConfigInformation.Connectiong))
            {
                string connstr = ConfigurationManager.AppSettings.Get("Connection");
                var helper = new DecryptAndEncryptionHelper(ConfigInformation.Key, ConfigInformation.Vector);
                connstr = helper.Decrypto(connstr);

                ConfigInformation.Connectiong = connstr;
            }
            IAppender[] appenders = log4net.LogManager.GetRepository().GetAppenders();
            foreach (IAppender appender in appenders)
            {
                if (appender.GetType() == typeof(AdoNetAppender))
                {
                    ((AdoNetAppender)appender).ConnectionString = ConfigInformation.Connectiong;
                    ((AdoNetAppender)appender).ActivateOptions();
                }
            }
        }