|
My understanding is that the connection is returned to the pool when you close it; you don't need to dispose it immediately. I keep a connection for the life of am application (some of which are Services that run 24/7 for months on end) and open/close as needed.
I don't dispose (Usually with via using) until the application is ready to exit.
Instantiating the same connections millions of times a day is not a good idea.
IDbConnection.Close Method -- The Close method rolls back any pending transactions. It then releases the connection to the connection pool, or closes the connection if connection pooling is disabled.
http://msdn.microsoft.com/en-us/library/system.data.idbconnection.close.aspx[^]
|
|
|
|
|
PIEBALDconsult wrote: My understanding is that the connection is returned to the pool when you close it; you don't need to dispose it immediately.
From the documentation for SqlConnection.close()
"Close and Dispose are functionally equivalent."
PIEBALDconsult wrote: I keep a connection for the life of am application (some of which are Services that run 24/7 for months on end) and open/close as needed.
Not sure what that means. But
1. You should close it or dispose it when you are done with it in the functional block. There is no point in holding on to the instance.
2. The fact that a service is 24x7 doesn't mean that the database won't need to be rebooted. And if you are actually holding on to the connection then the result will be an exception. At least with the pool (connection close/disposed immediately) you have the chance of recovering eventually. The pool doesn't recover connections in use and it only drops connections when a usage attempt results in an error that is the result of a failed connection.
PIEBALDconsult wrote: Instantiating the same connections millions of times a day is not a good idea.
Object instantiation is a trivial cost in modern OO languages. So that can't be what you are referring to.
Connection creation in a modern data center is rather insignificant. However that doesn't matter because unless you explicitly set up the connection pool to do otherwise the pool will be holding active connections. So opening a connection does nothing but retrieve it from the pool. So "instantiating" means nothing in this context.
|
|
|
|
|
jschell wrote: "Close and Dispose are functionally equivalent
That's easy to disprove. Dispose also clears the ConnectionString so it needs to be set again if you want to reuse the instance (which you shouldn't from a purely ivory tower point of view).
jschell wrote: You should close it or dispose it when you are done with it in the functional
block
I close it.
jschell wrote: is rather insignificant
So? I'll still avoid it when I can.
modified 10-Feb-13 23:51pm.
|
|
|
|
|
classy_dog wrote: 1. when do you recommend connection pooling be setup?
Unless you have explicitly changed the connection configuration in your connection url then pooling always exists in C#/.Net.
classy_dog wrote: 2. Does it make a difference if this connection pooling is a web, desktop, console or some other C# application?
They behavior of the application makes a difference. For example generally it is pointless to have a pool in a standalone client application. And if one expects a lot of stand alone client applications then it could actually be a detriment. For low volume servers pools provide no benefit.
For high volume servers a pool might increase the overall tps (transactions per second). Whether that increase is significant is another matter. It depends on actual usage. However it will often have some positive impact.
There is a downside to pooling in that you must understand the limitations as well as understand how it behaves. For example if you have 100 active connections in the pool and the database is bounced, then you have 100 stale connections. Consequently those will result in 100 exceptions when you attempt to use them because the pool does not test them before giving them to you. And there is a very good reason for not testing them because doing so would basically incur the same cost as creating the connection in the first place as well as not providing any surety that when you use the connection that it still wouldn't be stale (because the database might be bounced after the test and before use.)
classy_dog wrote: 3. Can you point me to a reference and or some me some code how to setup the connection pooling?
As noted the connection pool is already set up.
If you wish to tune it for your application(s) then you can modify the url. That is documented in the following.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx[^]
Keep in mind that you can have different urls to the same database. Each connection string represents a different pool.
If you want to attempt to deal with the stale pool problem then look to the SqlConnection.SqlConnection.ClearAllPools() method.
|
|
|
|
|
When a user clicks a mailto link outlook may open, when a user clicks callto skype may open. How can I subscribe to these "events" in my own apllication.
what I want to do is open a custom app from a callto link on a webpage which will then in turn dial out using TAPI.
The problem I have is subscribing to this event.
|
|
|
|
|
was this a windows application or web app? please specify the library
Jibesh V P
|
|
|
|
|
Since you have posted in C# forum, I am assuming your application is stand-alone desktop application.
When a mailto link is clicked, browser is responsible to open the default mail client on the computer. I don't think you can handle this event. One way to achieve this would be by making your program as the default email client (if it is an email client). This is how it will work for callto also. AFAIK, mailto is part of the standard while callto is proprietary and defined by skype and skype extensions for browsers.
Best wishes,
Navaneeth
|
|
|
|
|
We have an article[^] on the subject.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks Eddy,
That looks like what I need. I will take a look at it and see.
|
|
|
|
|
|
|
hi,
i'm using visual c# 2008 xpress, sql srver 2005 xpress
the dataset is ItemDataDS
that's what i do :
SA.ItemDataDSTableAdapters.tblItemDataTableAdapter taItemData;
ItemDataDS ds = new ItemDataDS();
DataTable dt = ds.Tables[tablename];
i create and populate an array of objects ao and do : dt.LoadDataRow(ao,true);
when i check ds (debug) i find the table and in the table i find the data
finally i do : taItemData.Update(ds);
this is done without and error but when i check the db-table no data was written
the TableAdapters insert-, update-, select- and delete-methods work as i added and updated one record with the dataset-designer.
the fill() method also works 'cause this record can be seen in the ds.
any suggestions what i'm doing wrong or what i can do analyze the problem ?
thanks in advance
|
|
|
|
|
Don't post the same thing in the forums and QA - it duplicates work and wastes time, which is rude.
Pick one, and stuck with it.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Hi,
You might need to set the insert, update and delete command for your dataadapter.
SqlCommandBuilder cmdbuilder;
cmdbuilder = new SqlCommandBuilder(dataAdapt);
dataAdapt.DeleteCommand = cmdbuilder.GetDeleteCommand(true);
dataAdapt.UpdateCommand = cmdbuilder.GetUpdateCommand(true);
dataAdapt.InsertCommand = cmdbuilder.GetInsertCommand(true);
Best Regards
Muthuraja
|
|
|
|
|
how to multiply combo box value with text box value in c# and also retrive in another text box that can be used for another addition of values
|
|
|
|
|
abhishek808000 wrote: combo box value Retrieve the value from the combo[^];
Double zeValueFromZeComboBox = Convert.ToDouble(comboBox1.SelectedValue);
Next, retrieve the value from the textbox;
Double zeValueFromZeTextBox = Convert.ToDouble(textBox1.Text);
Multiply and display result;
Double zeResult = zeValueFromZeComboBox * zeValueFromZeTextBox;
textBox2.Text = zeResult.ToString();
This is basic stuff, and you should be able to figure it out using the documentation. Are you doing a course on this stuff? Or learning it as a hobby?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Please use Parse or TryParse rather than Convert; think of the children.
|
|
|
|
|
it getting output is 0
my code is
Double a = Convert.ToDouble(cmbqua1.SelectedValue);
Double b = Convert.ToDouble(txtrt1.Text);
Double result1 = a * b;
txtpr1.Text = result1.ToString();
txtpr1.text shows 0 value
|
|
|
|
|
Use the ComboBox SelectedItem property instead of SelectedValue.
Double a = Convert.ToDouble(cmbqua1.SelectedItem);
Double b = Convert.ToDouble(txtrt1.Text);
Double result1 = a * b;
txtpr1.Text = result1.ToString();
Jibesh V P
|
|
|
|
|
thank you.. it works
|
|
|
|
|
Glad it works. but do try to spend some time debugging your application and do some google search... its always good to solve an issue by self and issues these are easy to be find by self.
Jibesh V P
|
|
|
|
|
Parse the Text values (they are strings in there, not actual numbers you can use) into an appropriate datatype, such as an Integer adn do your math with those values. See TryParseInt32.TryParse()[^] for more information and an example.
|
|
|
|
|
You will likely find that NumericUpDown s are more appropriate to the task.
|
|
|
|
|
Hi
I have 3 different projects (all in Windows Forms). I want to make a fourth form which will be the Menu form from which I can navigate to the other forms. I'm looking for a way to combine all these project to the fourth project so I'll be able to access the other forms from the Menu form. I tried the "add existing item" but the problem is that all the forms in all the projects are named Form1.cs and Form1.Designer.cs so it doesn't let me (although the forms have different names).
So how can I combine all these project? or how can I change the name of a cs file without doing any damage?
Thanks a lot.
|
|
|
|
|
You'll probably have to rename these files and change the class names to something more meaningful, then copy the files into the same project.
No, there is no easy and/or automated way to do this.
|
|
|
|