|
Hi All,
I am connecting to a SQL 2000 Server database by using a datareader.
I am getting this error.
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
1. How can I lengthen the time out on my connection?
2. How can I make sure there are no connections and that all connections are released by me and returned to the pool?
Thanks for any help.
Stephen
|
|
|
|
|
It would help if you could provide us with some code, and where the exception occurs.
|
|
|
|
|
|
is there anything special that needs to be done when interopping with objects of type System.__ComObject? without good docs, how do you know what to cast to if all u got is a C# type object?
|
|
|
|
|
It greatly depends on what you're doing. All types (doesn't matter which language, BTW) are IDispatch implementations unless you expose an interface differently using different enums for either the InterfaceTypeAttribute<?code> (for interfaces) or <code>ClassInterfaceAttribute (auto-generated class interface; never use auto-generated class interfaces, though).
When you cast an object to a COM-defined interface (attributed with ComImportAttribute ) a QueryInterface is actually performed using the interface to which you're trying to cast. This means you have to have some idea of what you're trying to cast, otherwise you can either cast it as IDispatch (if it's a dispatch object) or - at the very least - IUnknown , which honestly gives you anything useful.
As I've told many people, understanding COM interop with .NET well requires that you understand COM well. I would recommend picking up a book on COM programming, as well as a book on COM interop if you need further explanation.
There's also several good articles here on this site that explain bits and pieces, but the bigger pictures requires a deeper understanding of just how COM works and how .NET interop works with (and for) COM.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
I am trying to output a txt file to a Windows form in C# of course. I have coded how to read the file, that is not a problem anymore. And I can outpout it to the console. But I have been unsuccessful on how to output it on a Form instead of a console.
Can anyone help please?
A Newbie in tha block
|
|
|
|
|
Add a control (such as the Label or TextBox) to the form and set its Text property to the contents of the file.
Regards,
Alvaro
Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we. - George W. Bush
|
|
|
|
|
Thank you Alvaro for your response,
I am writing a program that reads records from a file of type txt containing stuffs like item name, quantity and prices. The first step is to simply read the file and output its containt on a windows form. The second step will be to compute the total cost of each item and post it the results on the form. I guess I have figured out how to do this second part ( well, i guess). But I am stuck on the first step.
This is what I have:
I have the class, reading the txt file, called PartFile. This class contains this function that is supposed to read the file (maybe typecast everything to string) and sent it to the Form.
public void ReadFile()
{
string line;
StreamReader file = new StreamReader("MyFile.txt");
while((line = file.ReadLine()) !=null)
//Console.WriteLine(line); ///commented out because I want to write the file to a Form, not Console
file.Close();
}
While reading my C# book I read about a ToString function, how can I implemente it here to read the file as strings?
Is that how I should code this function, is there anything I should do? how should I do it? Please, help me think through this.I got a brain storm now....can't find a way to get to the next level that I feel i can pretty much do. I just need to be able to read the file and post it to a form. I kind feel like i can move forward on my own (maybe) right after.
Thank, and i hope someone will help... Thank you Alvaro
A Newbie In Tha Block
|
|
|
|
|
Do this instead:
StreamReader file = new StreamReader("MyFile.txt");<br />
string contents = file.ReadToEnd();<br />
file.Close();
That's it, now you have the whole contents of the file in one string. Add a Label control to your form and do:
label.Text = contents;
Regards,
Alvaro
Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we. - George W. Bush
|
|
|
|
|
I have a class Client (client.cs) that is serializable and a class RemoteMethods (MarshalByRefObject) with a method public static Client getClient(int clientID). Ok... now the question... how to add a "remote" reference to Client class. I want to access this class without need to have the Client's dll on my client side I want to access this referencing it on another machine... This is possible?
Regards....
Wender Oliveira
.NET Programmer
|
|
|
|
|
Please clearify...
Wender Oliveira wrote: without need to have the Client's dll on my client side.
And another thing
Wender Oliveira wrote: how to add a "remote" reference to Client class
If you are trying to reference something in the client assembly from the server assembly your design is not right. That class must be in the shared assembly.
|
|
|
|
|
Sorry... lol
I want to make a new instance of a class that exists only on my remote server... I don't want to copy the dll that has this class inside to my client server...
Wender Oliveira
.NET Programmer
|
|
|
|
|
OK. That's more like it.
What you do is you create a library that has that class you want to use in both the client and the server. You then add a reference to the library in both the server and the client.
Another thing. If you want to have the implementation for the code hidden you can create an interface that matches the code (its a good practice to come up with the interface before hand ) and put the interface in the shared library.
|
|
|
|
|
Thanks Alex... This is what I want to know but not what I want to read. I'm doing like you said and I was hopeful to find another way... like webservice... you just add a web reference and all those classes can be found by vs.net ...
Thanks again...
Wender Oliveira
.NET Programmer
|
|
|
|
|
|
How can i change the caret color in a textbox?!! Is it possible?!
Thanks
|
|
|
|
|
I'm looking for the same thing. Well not really looking but I need a solution. Dont have time to look
|
|
|
|
|
|
I have a listview in detail mode which I use to display a subset of records from an SQL table. If the user changes the subset parameter I refresh the list with another set of lines.
My problem is that while the original population of the list is very fast (it is done in the dialog's constructor), the refreshes are quite slow - about 10 seconds for a 500 line data set.
I know the problem lies with the listview since if I comment out the listview code, the method executesd quite fast. I have tried:
begin/end update
setting enable=false and then true
setting visible=false and then true
None seem to have more than a small effect (about 10% difference).
Any suggestions?
the method's code:
...<br />
sqlCmd.CommandType = CommandType.StoredProcedure;<br />
SqlDataReader reader = sqlCmd.ExecuteReader();<br />
<br />
lvwLogDays.Items.Clear();<br />
<br />
while( reader.Read() )<br />
{<br />
DateTime Date = reader.GetDateTime( reader.GetOrdinal( "LogDate" ) );<br />
string strTemp = Date.ToString( "MM/dd/yyyy" );<br />
OpenDayLogData DayLogData = new OpenDayLogData();<br />
<br />
ListViewItem item = lvwLogDays.Items.Add( strTemp );<br />
strTemp = reader["CallLetters"].ToString().Trim();<br />
item.SubItems.Add( strTemp );<br />
<br />
strTemp = reader["LogStatus"].ToString().Trim();<br />
item.SubItems.Add( strTemp );<br />
<br />
DayLogData.LogID = Convert.ToInt32(reader["DF_LogID"].ToString(), 10);<br />
DayLogData.LogDayID = Convert.ToInt32(reader["DF_LogDayID"].ToString(), 10);<br />
item.Tag = DayLogData;<br />
}<br />
...
|
|
|
|
|
Calling ListView.BeginUpdate before clearing and adding items, and ListView.EndUpdate should help performance quite a bit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Actually I have the method (and one that follows this method - a sorter) bracketed by BeginUpdate() and EndUpdate() to no avail. As I wrote in the original, there seems to be about a 10% gain by using such a technique.
so the code goes something like this:
lvwLogDays.BeginUpdate();
RefreshList();
SortList();
lvwLogDays.EndUpdate();
Optionally, I have put lvwLogDays.Enabled=false/true bfroe/after the update calls.
|
|
|
|
|
You could also get a pretty good gain if you fetch all records first (say, into a DataSet ) and then build your list. This really depends on your wire speed and format, though (whether or not you'll see any gains).
One other thing is to make sure that your ListView doesn't specify a sort already if you're going to sort it later a la SortList . Do one or the other, but not both. Sorting the list after is most often faster when you have a large number of items.
Is the code you use for the first and future operations exactly the same (with the call to Clear ), i.e. you're using a DataReader to fetch the rows, etc.?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for the help.
I did replace the reader with a load into a DataTable and then 'foreached' out of it - no noticible difference in speed.
I have ensured the listview does not sort. We opted to sort after so we can perform sorts on the various columns if the user clicks a column head.
The method I cliped from (LoadLogList) is used both by the dialog's constructor and then by the refresh method, so it is used in 'first and future operations'. So I call the Clear() when I know the listview's item list is empty. I just moved the clear out of the method - no noticable difference.
I now do this:
lvwLogDays.Enabled=false;<br />
lvwLogDays.BeginUpdate();<br />
lvwLogDays.Items.Clear();<br />
LoadLogList();<br />
Resort( 0 );<br />
lvwLogDays.EndUpdate();<br />
lvwLogDays.Enabled=true;
|
|
|
|
|
Out of curiousity, are you by changing collecting data in a separate thread other than the one the ListView was created? If so, undefined problems can result. In such a case, you need to use Control.Invoke . The SDK documentation gives clear details and examples.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
This sorta reminds me of something I just came across also.
I really like the way items are added to the list when doing a Find in Microsoft Outlook 2003. The UI is very responsive, the CPU usuage is low and the items get added quickly. It would be nice if this was possible in .NET.
However, when iterating over items and adding them to a listview in .NET it is very slow. I have another thread that adds the items so that the main UI thread isn't blocked. I did use Control.Invoke to add each of the items and that was a bad idea to do an Invoke for each item that is to be added. It completely bogged down the message pump and locked up the UI.
If anyone has any suggestions I'm all ears. I believe the problem lies in the synchronization and invokations in .NET that need to occur when adding items to a list view in a seperate thread.
BeginUpdate and EndUpdate wasn't really an option for me becaues that prevents the UI from being drawn. The search process I am performing can take some time so I want to provide immediate feedback about items that I have found.
-
Drew
|
|
|
|