我试图确定我是否有数据库连接泄漏.所以我需要查看打开连接的数量.我有一些简单的测试代码会产生泄漏:
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
我应该改变什么以实际看到连接?
回答
我已经批准了以下答案.即使它不使用性能工具,它对我的使用也足够好.底线是我想看看打开网页后仍有多少连接打开,这就行了.
有可能做这样的事情:
def foo(bar, success)
success = True
# ...
>>> success = False
>>> foo(bar1, success)
>>> success
True
Run Code Online (Sandbox Code Playgroud)
Python有没有params,或者是一种简单的方法来模拟它们?(除了弄乱父母的堆栈帧.)
我正在尝试编译游戏,但得到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) 在我的应用程序中,我需要在memroy和磁盘中存储一些简单的数据.在我的情况下,真正的数据库将是过度的,所以我需要更轻的数据库来处理简单的数据持久性要求.我自己做了一些谷歌搜索,发现了一些有趣的东西,如DBM和DBI CVS等,但由于有太多选项,所以我很难做出实际选择,所以我想在这里问你这个"最佳实践",如perl中的轻量级数据持久解决方案.
PHP内置了_get和_set函数.为每个变量编写自己的get和set函数是否更好,或者使用内置函数和if if if if?每种方法的优缺点是什么?
程序加载时是否有机制或技巧来运行函数?
我想要实现的目标......
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(没有任何平台/编译器特定)
我有一个优惠券模型,它有一些字段来定义它是否处于活动状态,以及一个只返回实时优惠券的自定义管理器.优惠券有一个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) 考虑以下代码:
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) 我已经读过一些模糊的陈述,即虚拟继承不提供COM所需的内存结构,因此我们必须使用普通继承.发明虚拟继承来处理钻石问题.
有人能告诉我这两种继承方法之间存储结构细节差异的说明吗?而虚拟继承不适合COM 的关键原因.一张照片最好.
非常感谢.
我尝试在展开折叠或展开时交换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)
有谁知道如何使这个工作?
c++ ×2
sql ×2
accessor ×1
aggregates ×1
android ×1
asp.net ×1
c ×1
com ×1
connection ×1
count ×1
database ×1
django ×1
gcc ×1
get ×1
java ×1
orm ×1
perl ×1
php ×1
portability ×1
python ×1
set ×1
swing ×1
swingworker ×1
tdd ×1
unit-testing ×1