示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews().AddRazorRuntimeCompilation();
            services.AddSession();
            services
            .AddSingleton(Configuration)
            .AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            //*=== SETTING CONNECTION STRING ===*//
            string dbConn = "";

            if (HostEnvironment.IsDevelopment())
            {
                dbConn = Configuration.GetConnectionString("EKanbanWebDBConnection");
            }
            if (HostEnvironment.IsProduction())
            {
                DbConf db = new DbConf(Configuration, HostEnvironment);
                dbConn = db.GetConnectionString();
            }
            services.AddDbContext <EKanbanWebDBContext>(options =>
                                                        options.UseSqlServer(dbConn,
                                                                             sqlServerOptionsAction: sqlOptions =>
            {
                sqlOptions.EnableRetryOnFailure();
            }));
            //=========================================

            services.Configure <IISServerOptions>(options =>
            {
                options.AutomaticAuthentication = false;
            });
        }
示例#2
0
        public DataTable ExecQuery(string sp, List <SqlParameter> parameters)
        {
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            try
            {
                using SqlConnection con = new SqlConnection(_db.GetConnectionString());
                con.Open();

                using (SqlCommand comm = new SqlCommand("SET ARITHABORT ON", con))
                {
                    comm.ExecuteNonQuery();
                }

                SqlCommand cmd = new SqlCommand(sp, con);
                foreach (SqlParameter param in parameters)
                {
                    cmd.Parameters.Add(param);
                }

                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = 120;
                SqlDataAdapter da = new SqlDataAdapter
                {
                    SelectCommand = cmd
                };

                da.Fill(ds);
                dt = ds.Tables[0];
                con.Close();
            }
            catch (Exception e)
            {
            }
            return(dt);
        }