问题列表 - 第29173页

如何衡量打开数据库连接的数量

我试图确定我是否有数据库连接泄漏.所以我需要查看打开连接的数量.我有一些简单的测试代码会产生泄漏:

protected void Page_Load(object sender, EventArgs e)
{
  for(int i = 0; i < 100; i++)
  {
    SqlConnection sql = new SqlConnection(@"Data Source=.\SQLExpress;UID=sa;PWD=fjg^%kls;Initial Catalog=ABC");
    sql.Open();
  }

}
Run Code Online (Sandbox Code Playgroud)

注意没有.Close,这在快速连续运行3次后确实会崩溃.

为了测量泄漏,我正在运行性能监视器并测量SQLServer:常规统计/用户连接:

替代文字http://www.yart.com.au/stackoverflow/counter.png

但是,当我运行我的代码时,这些似乎是零:

替代文字http://www.yart.com.au/stackoverflow/counter1.jpg

我应该改变什么以实际看到连接?

回答

我已经批准了以下答案.即使它不使用性能工具,它对我的​​使用也足够好.底线是我想看看打开网页后仍有多少连接打开,这就行了.

sql database asp.net connection

9
推荐指数
1
解决办法
2857
查看次数

Python out params?

有可能做这样的事情:

def foo(bar, success)
    success = True
    # ...

>>> success = False
>>> foo(bar1, success)
>>> success
True
Run Code Online (Sandbox Code Playgroud)

Python有没有params,或者是一种简单的方法来模拟它们?(除了弄乱父母的堆栈帧.)

python

1
推荐指数
1
解决办法
342
查看次数

编译时出现C++错误

我正在尝试编译游戏,但得到100多个错误,如:

C:\Users\AppData\Local\Temp\cctQCagR.o: In function `load_image(std::string)':
main.cpp:(.text+0x4bd4): undefined reference to `std::string::c_str() const'
C:\Users\Bill\AppData\Local\Temp\cctQCagR.o: In function `createShip(float, float)':
main.cpp:(.text+0x4da4): undefined reference to `std::allocator<char>::allocator()'
main.cpp:(.text+0x4dbc): undefined reference to `std::basic_string<char, std::char_tra
its<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> cons
t&)'
main.cpp:(.text+0x4de4): undefined reference to `std::basic_string<char, std::char_tra
its<char>, std::allocator<char> >::~basic_string()'
main.cpp:(.text+0x4e04): undefined reference to `std::basic_string<char, std::char_tra
its<char>, std::allocator<char> >::~basic_string()'
main.cpp:(.text+0x4e1c): undefined reference to `std::allocator<char>::~allocator()'
main.cpp:(.text+0x4e28): undefined reference to `std::allocator<char>::allocator()'
main.cpp:(.text+0x4e40): undefined reference to `std::basic_string<char, std::char_tra
its<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> cons
t&)'
main.cpp:(.text+0x4e60): undefined reference to `std::allocator<char>::~allocator()' …
Run Code Online (Sandbox Code Playgroud)

c++ gcc

27
推荐指数
2
解决办法
4万
查看次数

在perl中寻找轻量级数据持久性解决方案

在我的应用程序中,我需要在memroy和磁盘中存储一些简单的数据.在我的情况下,真正的数据库将是过度的,所以我需要更轻的数据库来处理简单的数据持久性要求.我自己做了一些谷歌搜索,发现了一些有趣的东西,如DBM和DBI CVS等,但由于有太多选项,所以我很难做出实际选择,所以我想在这里问你这个"最佳实践",如perl中的轻量级数据持久解决方案.

perl

10
推荐指数
2
解决办法
3414
查看次数

PHP的_get&_set或每个变量的唯一get和set函数?

PHP内置了_get和_set函数.为每个变量编写自己的get和set函数是否更好,或者使用内置函数和if if if if?每种方法的优缺点是什么?

php encapsulation get accessor set

6
推荐指数
1
解决办法
3624
查看次数

你能在c初始化时运行一个函数吗?

程序加载时是否有机制或技巧来运行函数?

我想要实现的目标......

void foo(void)
{
}

register_function(foo);
Run Code Online (Sandbox Code Playgroud)

但显然register_function不会运行.

所以C++中的一个技巧是使用初始化来运行函数

就像是

int throwaway = register_function(foo);
Run Code Online (Sandbox Code Playgroud)

但这在C中不起作用.所以我正在寻找一种方法来使用标准C(没有任何平台/编译器特定)

c portability initialization

6
推荐指数
1
解决办法
3391
查看次数

Django - 计算相关模型的子集 - 需要为每个项目注释活动优惠券的数量

我有一个优惠券模型,它有一些字段来定义它是否处于活动状态,以及一个只返回实时优惠券的自定义管理器.优惠券有一个FK到项目.

在对项目的查询中,我试图注释可用的有效优惠券的数量.但是,Count聚合似乎在计算所有优惠券,而不仅仅是活跃优惠券.

# models.py
class LiveCouponManager(models.Manager):
    """
    Returns only coupons which are active, and the current
    date is after the active_date (if specified) but before the valid_until
    date (if specified).
    """
    def get_query_set(self):
        today = datetime.date.today()
        passed_active_date = models.Q(active_date__lte=today) | models.Q(active_date=None)
        not_expired = models.Q(valid_until__gte=today) | models.Q(valid_until=None)
        return super(LiveCouponManager,self).get_query_set().filter(is_active=True).filter(passed_active_date, not_expired)

class Item(models.Model):
    # irrelevant fields

class Coupon(models.Model):
    item = models.ForeignKey(Item)
    is_active = models.BooleanField(default=True)
    active_date = models.DateField(blank=True, null=True)
    valid_until = models.DateField(blank=True, null=True)
    # more fields

    live = LiveCouponManager() # defined first, should …
Run Code Online (Sandbox Code Playgroud)

sql django orm count aggregates

5
推荐指数
1
解决办法
934
查看次数

如何使SwingWorker代码可测试

考虑以下代码:

public void actionPerformed(ActionEvent e) {
    setEnabled(false);
    new SwingWorker<File, Void>() {

        private String location = url.getText();

        @Override
        protected File doInBackground() throws Exception {
            File file = new File("out.txt");
            Writer writer = null;
            try {
                writer = new FileWriter(file);
                creator.write(location, writer);
            } finally {
                if (writer != null) {
                    writer.close();
                }
            }
            return file;
        }

        @Override
        protected void done() {
            setEnabled(true);
            try {
                File file = get();
                JOptionPane.showMessageDialog(FileInputFrame.this,
                    "File has been retrieved and saved to:\n"
                    + file.getAbsolutePath());
                Desktop.getDesktop().open(file);
            } catch (InterruptedException …
Run Code Online (Sandbox Code Playgroud)

java tdd swing unit-testing swingworker

16
推荐指数
2
解决办法
1901
查看次数

为什么我们不能在COM中使用"虚拟继承"?

我已经读过一些模糊的陈述,即虚拟继承不提供COM所需的内存结构,因此我们必须使用普通继承.发明虚拟继承来处理钻石问题.

有人能告诉我这两种继承方法之间存储结构细节差异的说明吗?而虚拟继承不适合COM 的关键原因.一张照片最好.

非常感谢.

c++ com

10
推荐指数
2
解决办法
2208
查看次数

折叠或展开时,Android expandablelistview组/父级背景图像会发生变化

我尝试在展开折叠或展开时交换expandablelistview组背景图像.但是背景图像没有正确交换.例如,当我展开第一组时,第二组或第三组的背景会被交换.

我正在使用RelativeLayout(组布局)和SimpleExpandableListAdapter(适配器).这是我做的:

// Create 2 drawable background. One for collapse and one for expand
private Drawable collapseBG, expandBG;
private ExpandableListView myView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    collapseBG = getResources().getDrawable(R.drawable.box_bg_header_collapse);
    expandBG = getResources().getDrawable(R.drawable.box_bg_header_expand);
    myView = (ExpandableListView) findViewById(R.id.myView);
}

myView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
    public void onGroupCollapse(int groupPosition_c) {
        myView.getChildAt(groupPosition_c).setBackgroundDrawable(collapseBG);
    }
});

myView.setOnGroupExpandListener (new ExpandableListView.OnGroupExpandListener() {
    public void onGroupExpand(int groupPosition_e) {
        myView.getChildAt(groupPosition_e).setBackgroundDrawable(expandBG);
    }
});
Run Code Online (Sandbox Code Playgroud)

有谁知道如何使这个工作?

android expandablelistview

3
推荐指数
1
解决办法
1万
查看次数