|
I am trying to fix a bug and I have come across an unusual obstacle.
There is a select query which retrieves about 3,369,957 records. This query is set as the SelectCommand of a SqlDataAdapter and executed by calling Fill method. However, during debugging nothing seems to happen once the debugger steps into Fill method. The code is inside a try block and no exception is thrown. The debugger just does not pass the Fill method. I am lost. Any ideas?
|
|
|
|
|
CodingYoshi wrote: The debugger just does not pass the Fill method
You mean it just hangs on the statement. If so, I would guess it takes quite some time to fetch the data from the db and to populate the table. You could check from task manager if the debugger is eating cpu and memory to verify it's working.
|
|
|
|
|
It is a weird situation. It takes forever on my machine but when I run it on another machine it takes a lot less time. Just to make things more weird, I wrote a small console application and ran the same query and it executed under the same time as it does on other machines.
Not sure why it would run so slow on my machine when the code is run from the application but when run from a different application then it is executed a lot faster. mmmm....thinking...ghosts...
|
|
|
|
|
Did you check memory consumption. First guess would be that your machine could be swapping. Perhaps you're just on the limit of swapping with the console app and if you have a gui, it goes over the limit or then some other process is eating up the memory. You could use task manager to observe the situation... On the other hand, memory chip prices have risen lately, perhaps they have somekind of conspiracy how to make people buy more RAM
|
|
|
|
|
I just noticed that it is not freezing but loading data. For some reason the developer decided to throw all data into memory (consuming up to 638M!), hence the reason why it is taking forever on my machine because the other machine is a powerful server.
|
|
|
|
|
Exactly, in your original post you said that the program is using SqlDataAdapter.Fill to populate the dataset or datatable. Those are memory resident.
That's also the reason I suggested to watch memory consumption and why I suspected your machine is swapping.
|
|
|
|
|
which retrieves about 3,369,957 records
You said it yourself. If your retrieving that many records, each being, say 500 bytes each, you're loading 1,684,978,500 (1.6GB!) of data into memory. Your machine is going to be swapping pages out to disk for ages!
Really, I'd go smack the guy who wrote that code. Unless you're doing something with every bit of that data, you shouldn't be retrieving that much data from the server, let alone putting it all in a DataSet/DataTable object. Besides the HUGE memory requirements, if this record count continues to grow, you'll eventually run either the server out of memory, or, more likely, the process addressable space, which is 2GB.
|
|
|
|
|
because your console application is just displaying the data using (I think) data reader, right ?
if thats the case then,
Reader is a forward only cursor so it will just fetch the chunk of rows and then sends them for display and forget it, until all the rows are displayed.
while the SqlDataAdapter will actually hold the complete result in the memory. so it will take some time also if you have less RAM then hdd paging will take even more time. so try to divide the rows, so that your Dataset dont have to hold the whole table. (i.e. some section wise or category wise)
|
|
|
|
|
Your problem comes from the fact that you are loading 3 millions records in memory. You should consider using a DataReader instead of data set.
|
|
|
|
|
I have a program written in C# and from it I want to start another file ,some run.batch (which has a java program written behind) . Problem is that the 2nd program(a text processor) has an error when it is processing a text in 0:00:00 (no time) . But it works. I just have to click cancel debugging, so I can do my job further.
2nd program is closed source and cannot be modified.
What I want to do is to catch the errors from my main program if possible.
Thank you.
|
|
|
|
|
There only way you could do that would be to constantly poll the windows, looking for a window with the proper title. This requires enumerating the open windows using FindWindow[^], EnumChildWindows[^]
But, you have a bigger problem. Java windows do not use standard Windows controls, so you really can't send keystrokes to them. The best you can do is send keystrokes to the parent Windows window and hope for the best.
|
|
|
|
|
ipstefan wrote: What I want to do is to catch the errors from my main program if possible.
So far, we can not do this since no way to catch the exception from other process. We can redirect the error output and check the error code. Nevertheless, this is not what you want.
I Love KongFu~
|
|
|
|
|
you can use following code to run any extrenal file( batch/exe)
Process p = new Process();
p.StartInfo.FileName = pathToCommandLineTool;
p.StartInfo.Arguments = commandLineInputParameters;
p.Start();
p.WaitForExit();
p.Close()
|
|
|
|
|
man...I already use this.
string targetDir;
targetDir = string.Format(@"E:\desk\baaaars\copy\copy\romm");
p = new Process();
p.StartInfo.WorkingDirectory = targetDir;
p.StartInfo.FileName = "run.bat";
// p.StartInfo.Arguments = string.Format("C-Sharp Console application");
p.StartInfo.CreateNoWindow = false;
p.Start();
p.WaitForExit();
read the content not just the title next time.
|
|
|
|
|
Could you wrap the second program into another one? For example:
public class YourJavaClass {
public static void main(String[] args) {
try {
YourSecondAppMainClass.main(args);
} catch (Throwable t) {
}
}
} This isn't exactly catching the exception from C#, but this is where you can begin. You have the exception information, so you may print something predetermined to System.err and handle it in your C# application.
Note that you'll have to modify run.bat to call your class, but you should leave all other commands in the batch file as-is.
|
|
|
|
|
run.bat launches the java programs in .jar format(tnttolem.jar,towp.jar,txttoint.jar) - also run.bat uses a perl program too.
|
|
|
|
|
This shouldn't be a problem. You'll just need to add the three JAR files to the classpath, and proceed as I explained previously. If you don't know what's the main method, check the MANIFEST.MF file inside the main JAR, where you'll find it mentioned. If not, you'll find it somewhere in the batch file, but you may have to dig deeper.
(You could post the batch file if you want, and I'll try to help you with it.)
|
|
|
|
|
Hi
I have a datagrid and I would like to either replace zero's with a space or suppress them. I have tried just putting in a space but that did not work. The field used to have -Infinity in it so I forced a zero with this line
if (Grid_Property.Rows[i].Cells["pDiff"].Value.ToString() == "-Infinity")
{
Grid_Property.Rows[i].Cells["pDiff"].Value = "";
}
I tried to add to string in the if statement but that did not work see below
if (Grid_Property.Rows[i].Cells["pDiff"].Value.ToString() == "-Infinity")
{
Grid_Property.Rows[i].Cells["pDiff"].Value.ToString = "";
}
Any help would be appreciated
|
|
|
|
|
One way to do what I think you want to do is to handle the CellFormatting Event of the DataGridView
Something like this.
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.Value == null)
{
return;
}
DataGridViewColumn col = this.dataGridView1.Columns[e.ColumnIndex];
if (col.DataPropertyName == "pDiff")
{
if (e.Value.ToString() == "-Infinity")
{
e.Value = "";
e.FormattingApplied = true;
}
}
}
Hope this helps, or, I have at least understood your problem correctly.
Henry Minute
If you open a can of worms, any viable solution *MUST* involve a larger can.
|
|
|
|
|
Hi Thank you for the reply, I tried the code but it does not seem to be recognized I think it is because I have to double click the event and then add the code? I have real newbie question, how do I find the events to add. I did it before but can't seem to remember. Also if my datagrid name is Grid_Property where would I insert than in your example. Sorry for the beginner questions.
Thanks
|
|
|
|
|
Ok. We all have to start somewhere.
1. Make sure your Form with the DataGridView is visible in the designer with the DataGridView selected.
2. Make sure that you can see the Properties Window. If you can't then select it from the View Menu in VS or, a good tip, press F4.
3. At the top of the Properties Window there are several icons, click on the lightening bolt. This will take you to the events for the selected control, hopefully
your DataGridView . If not select it now.
4. The events can be organised in many ways. Alphabetically or in categories for example, so I cannot tell you exactly where the CellFormatting event
will be on your system. Search for it, and double click on it.
5. The designer will switch to code view with an empty event handler method for the CellFormatting event. Like this:
private void Grid_Property_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
}
6. Put your code between the braces. Your code should look like this:
if (e.Value == null)
{
return;
}
DataGridViewColumn col = this.Grid_Property.Columns[e.ColumnIndex];
if (col.DataPropertyName == "pDiff")
{
if (e.Value.ToString() == "-Infinity")
{
e.Value = "";
e.FormattingApplied = true;
}
}
Try that.
Henry Minute
If you open a can of worms, any viable solution *MUST* involve a larger can.
|
|
|
|
|
That worked, Thank you very much for the reply, and the guidence
|
|
|
|
|
Given the following code:
FileSystemWatcher m_watcher = new FileSystemWatcher();
private void MyMethod()
{
m_watcher.BeginInit();
m_watcher.Filter = "*myfile*.*";
m_watcher.IncludeSubdirectories = false;
m_watcher.Path = "C:\\MyEwatchedFolder";
m_watcher.NotifyFilter = NotifyFilters.LastWrite;
m_watcher.Changed += new FileSystemEventHandler(watcher_Changed);
m_watcher.EndInit();
m_watcher.EnableRaisingEvents = true;
}
void watcher_Changed(object sender, FileSystemEventArgs e)
{
FileSystemWatcher watcher = sender as FileSystemWatcher;
if (e.ChangeType == WatcherChangeTypes.Changed)
{
MessageBox.Show(string.Format("File!\n\n{0}", e.FullPath));
}
}
The Changed handler is getting called twice. I've looked all over googkle and can't find a reason or a way to fix it.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Have to tried increasing the FSW's InternalBufferSize?? It must be a multiple of the O/S page size(?? I think!). Default is 8KB. Keep in mind that each event that is internally queued needs 16 + (2 * filename length) bytes to store, so if you're encountering long filenames, you could overflow the buffer and not know anything about it.
|
|
|
|
|
The file names are approximately 30 characters long, but I'm only throwing one at a time at the application as a test, so I don't think the buffer would be filling up, even at the default 8k size.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|