473,287 Members | 1,651 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Help! My window application won't close.

I have a Window based application that shows up still running in the task
manager when I close it. It reaches the "this.close" statement and then it
stops at the "}" at the section of the following code after the
"Application.Run(new VMSMain());":
[STAThread]
static void Main()
{
Application.Run(new VMSMain());
}

I can't figure this one out at all. I would really appreciate some help
with this one.
Thanks, Alpha

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace VMS
{
/// <summary>
/// Summary description for VMSMain.
/// </summary>
public class VMSMain : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private SqlConnection conDB;
private SqlCommand scUpdate, scGetPath;
private string strATSPath, NewATS;
private System.Windows.Forms.Label label1;

[STAThread]
static void Main()
{
Application.Run(new VMSMain());
}

public VMSMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//Connect to VMS DB
// string conStr = @"Server=DEVELOPMENT\NetSDK; user id=tis; password=tis;
database = VMS";
// string conStr = @"Server=WENDI; user id=tis; password=tis; database =
VMS";
string conStr = @"Server=Support\NetSDK; user id=tis; password=tis;
database = VMS";

conDB = new SqlConnection(conStr);

try
{
conDB.Open();
scUpdate = conDB.CreateCommand();
conDB.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error connecting to the database server. VMS can't run
with out database connection and VMS will close. " + ex.ToString()+
"Please contact your support person.", "VMS - Database Open Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();

}
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(VMSMain));
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(80, 104);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(304, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Updating database. Please wait..............";
//
// VMSMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(496, 264);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.MaximizeBox = false;
this.Name = "VMSMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "VMS - Updating Database ";
this.Closing += new
System.ComponentModel.CancelEventHandler(this.vmsM ain_Closing);
this.Load += new System.EventHandler(this.VMSMain_Load);
this.ResumeLayout(false);

}
#endregion

private void button1_Click(object sender, System.EventArgs e)
{
}

private void vmsMain_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// conDB.Close();
}

private void VMSMain_Load(object sender, System.EventArgs e)
{
string[] ATSFiles;
bool NoFiles = false;
this.Show();
Cursor.Current = Cursors.WaitCursor;
// this.Show();
// MessageBox.Show("Updating VMS database. Please
wait.....................", "Updating");

//sdaUpdate = new SqlDataAdapter();
//GET THE ats file path from the DB
try
{
conDB.Open();
scGetPath = new SqlCommand("select LogFilePath from Admin", conDB);
strATSPath = scGetPath.ExecuteScalar().ToString();
strATSPath = strATSPath.Replace(@"\", @"\\");
conDB.Close();

}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS file path : " + ex.ToString()+
"Please contact your support person.", "VMS - ATS file path error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

//Get the latest ATS Access DB file name
try
{//@"C:\\VMS\\VMSDB"
ATSFiles = Directory.GetFiles(strATSPath, "Ats*Db.mdb");
if(ATSFiles.Length <= 0)
NoFiles = true;
else
{
NoFiles = false;
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
NewATS = NewATS.Replace(@"\\", @"\");
}
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS Access database files : " +
ex.ToString()+
"Please contact your support person.", "VMS - ATS files Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

if (!NoFiles)
{
try
{
//Begin Transaction
// SqlTransaction DbUpdateTransaction = conDB.BeginTransaction();
//
// scUpdate.Transaction = DbUpdateTransaction;

//Save the Previous readings
// scUpdate.CommandType = CommandType.StoredProcedure;
// scUpdate.CommandText = "SavePrevOdo";
// int row = scUpdate.ExecuteNonQuery();
conDB.Open();
int row;
//Insert new vehicle from the ATS Access database
scUpdate.CommandType = CommandType.Text;
scUpdate.CommandText = "INSERT INTO VehDetail(VName, LastOdometerDate,
LastOdometerReading)"+
" SELECT [d_RemoteName],CAST(MAX([d_DateTime]) AS DATETIME),
CAST(MAX([d_OdometerTenths]) AS INT(4))"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', '" +
NewATS + "';'Admin';'', DATA)"+
" WHERE [d_RemoteName] NOT IN(SELECT VNAME FROM VehDetail)"+
" GROUP BY [d_RemoteName]";
row = scUpdate.ExecuteNonQuery();

//Update the last date the odometer was read for each vehicle
scUpdate.CommandText = "UPDATE VehDetail SET VehDetail.LastOdometerDate
= (SELECT CAST(MAX([d_DateTime]) AS DATETIME)"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','"+
NewATS + "';'Admin';'', DATA)"+
" WHERE (d_RemoteName = VehDetail.VName))";
row = scUpdate.ExecuteNonQuery();

//Update the odometer at the last date the reading was taken
scUpdate.CommandText = "UPDATE VehDetail SET
VehDetail.LastOdometerReading ="+
" (SELECT CAST(MAX([d_OdometerTenths]) AS INT(4)) FROM
OPENROWSET('Microsoft.Jet.OLEDB.4.0','"+
NewATS + "';'Admin';'', DATA)"+
" WHERE (d_RemoteName = VehDetail.VName and DATEDIFF(SS,
CAST([d_DateTime] AS DATETIME), " +
"VehDetail.LastOdometerDate)=0))";
row = scUpdate.ExecuteNonQuery();

// DbUpdateTransaction.Commit();//Commit the transaction

}
catch(Exception ex)
{
MessageBox.Show("Error updating the database from ATS Access Database :
" + ex.ToString(), "Database Update Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}
// finally
// {
//
// }

conDB.Close();

try
{
SqlCommand scRetMaint = conDB.CreateCommand();
scRetMaint.CommandType = CommandType.StoredProcedure;
scRetMaint.CommandText = "ReturnMaintDued";
conDB.Open();
scRetMaint.ExecuteNonQuery();
scRetMaint.CommandType = CommandType.Text;
scRetMaint.CommandText = "select count(*) from MaintenanceDued";
int rowCount = (int)scRetMaint.ExecuteScalar();
conDB.Close();
Cursor.Current = Cursors.Default;
if (rowCount > 0)
{
this.Hide();
Form frmMD = new MaintDued(conDB);
frmMD.ShowDialog();
this.Close();
}
else
{
MessageBox.Show("There is no maintenance dued for any vehicle at this
time.", "VMS - No Maintenance Dued",
MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
Form frmVeh = new vmsHome(conDB);
frmVeh.ShowDialog();
this.Close();
}
}//end try
catch(Exception ex)
{
MessageBox.Show("Error obtaining the count for number of vehicels dued
for maintenance." + ex.ToString(), "Database Update Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}//end catch
}// end if (!NoFiles)
else if (NoFiles)
{
MessageBox.Show("There is no ATS database files found in the directory
specified.", "VMS - No ATS database files",
MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
Form frmVeh = new vmsHome(conDB);
frmVeh.ShowDialog();
this.Close();
}//END else if (NoFiles)

//this.Close();
}
}
}

Nov 17 '05 #1
1 5466
Ok, I found the error. I put the "this.show" at the wrong place. It was at
the end of VMSMain(). I removed it and it works fine now.

"Alpha" wrote:
I have a Window based application that shows up still running in the task
manager when I close it. It reaches the "this.close" statement and then it
stops at the "}" at the section of the following code after the
"Application.Run(new VMSMain());":
[STAThread]
static void Main()
{
Application.Run(new VMSMain());
}

I can't figure this one out at all. I would really appreciate some help
with this one.
Thanks, Alpha

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace VMS
{
/// <summary>
/// Summary description for VMSMain.
/// </summary>
public class VMSMain : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private SqlConnection conDB;
private SqlCommand scUpdate, scGetPath;
private string strATSPath, NewATS;
private System.Windows.Forms.Label label1;

[STAThread]
static void Main()
{
Application.Run(new VMSMain());
}

public VMSMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//Connect to VMS DB
// string conStr = @"Server=DEVELOPMENT\NetSDK; user id=tis; password=tis;
database = VMS";
// string conStr = @"Server=WENDI; user id=tis; password=tis; database =
VMS";
string conStr = @"Server=Support\NetSDK; user id=tis; password=tis;
database = VMS";

conDB = new SqlConnection(conStr);

try
{
conDB.Open();
scUpdate = conDB.CreateCommand();
conDB.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error connecting to the database server. VMS can't run
with out database connection and VMS will close. " + ex.ToString()+
"Please contact your support person.", "VMS - Database Open Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();

}
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(VMSMain));
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(80, 104);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(304, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Updating database. Please wait..............";
//
// VMSMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(496, 264);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.MaximizeBox = false;
this.Name = "VMSMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "VMS - Updating Database ";
this.Closing += new
System.ComponentModel.CancelEventHandler(this.vmsM ain_Closing);
this.Load += new System.EventHandler(this.VMSMain_Load);
this.ResumeLayout(false);

}
#endregion

private void button1_Click(object sender, System.EventArgs e)
{
}

private void vmsMain_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// conDB.Close();
}

private void VMSMain_Load(object sender, System.EventArgs e)
{
string[] ATSFiles;
bool NoFiles = false;
this.Show();
Cursor.Current = Cursors.WaitCursor;
// this.Show();
// MessageBox.Show("Updating VMS database. Please
wait.....................", "Updating");

//sdaUpdate = new SqlDataAdapter();
//GET THE ats file path from the DB
try
{
conDB.Open();
scGetPath = new SqlCommand("select LogFilePath from Admin", conDB);
strATSPath = scGetPath.ExecuteScalar().ToString();
strATSPath = strATSPath.Replace(@"\", @"\\");
conDB.Close();

}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS file path : " + ex.ToString()+
"Please contact your support person.", "VMS - ATS file path error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

//Get the latest ATS Access DB file name
try
{//@"C:\\VMS\\VMSDB"
ATSFiles = Directory.GetFiles(strATSPath, "Ats*Db.mdb");
if(ATSFiles.Length <= 0)
NoFiles = true;
else
{
NoFiles = false;
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
NewATS = NewATS.Replace(@"\\", @"\");
}
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS Access database files : " +
ex.ToString()+
"Please contact your support person.", "VMS - ATS files Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

if (!NoFiles)
{
try
{
//Begin Transaction
// SqlTransaction DbUpdateTransaction = conDB.BeginTransaction();
//
// scUpdate.Transaction = DbUpdateTransaction;

//Save the Previous readings
// scUpdate.CommandType = CommandType.StoredProcedure;
// scUpdate.CommandText = "SavePrevOdo";
// int row = scUpdate.ExecuteNonQuery();
conDB.Open();
int row;
//Insert new vehicle from the ATS Access database
scUpdate.CommandType = CommandType.Text;
scUpdate.CommandText = "INSERT INTO VehDetail(VName, LastOdometerDate,
LastOdometerReading)"+
" SELECT [d_RemoteName],CAST(MAX([d_DateTime]) AS DATETIME),
CAST(MAX([d_OdometerTenths]) AS INT(4))"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', '" +
NewATS + "';'Admin';'', DATA)"+
" WHERE [d_RemoteName] NOT IN(SELECT VNAME FROM VehDetail)"+
" GROUP BY [d_RemoteName]";
row = scUpdate.ExecuteNonQuery();

//Update the last date the odometer was read for each vehicle
scUpdate.CommandText = "UPDATE VehDetail SET VehDetail.LastOdometerDate
= (SELECT CAST(MAX([d_DateTime]) AS DATETIME)"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','"+
NewATS + "';'Admin';'', DATA)"+
" WHERE (d_RemoteName = VehDetail.VName))";
row = scUpdate.ExecuteNonQuery();

//Update the odometer at the last date the reading was taken
scUpdate.CommandText = "UPDATE VehDetail SET
VehDetail.LastOdometerReading ="+
" (SELECT CAST(MAX([d_OdometerTenths]) AS INT(4)) FROM
OPENROWSET('Microsoft.Jet.OLEDB.4.0','"+
NewATS + "';'Admin';'', DATA)"+
" WHERE (d_RemoteName = VehDetail.VName and DATEDIFF(SS,
CAST([d_DateTime] AS DATETIME), " +
"VehDetail.LastOdometerDate)=0))";
row = scUpdate.ExecuteNonQuery();

// DbUpdateTransaction.Commit();//Commit the transaction

}
catch(Exception ex)
{
MessageBox.Show("Error updating the database from ATS Access Database :
" + ex.ToString(), "Database Update Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}
// finally
// {
//
// }

conDB.Close();

try
{
SqlCommand scRetMaint = conDB.CreateCommand();
scRetMaint.CommandType = CommandType.StoredProcedure;
scRetMaint.CommandText = "ReturnMaintDued";
conDB.Open();
scRetMaint.ExecuteNonQuery();
scRetMaint.CommandType = CommandType.Text;
scRetMaint.CommandText = "select count(*) from MaintenanceDued";
int rowCount = (int)scRetMaint.ExecuteScalar();
conDB.Close();
Cursor.Current = Cursors.Default;
if (rowCount > 0)
{
this.Hide();
Form frmMD = new MaintDued(conDB);
frmMD.ShowDialog();
this.Close();
}
else
{
MessageBox.Show("There is no maintenance dued for any vehicle at this
time.", "VMS - No Maintenance Dued",
MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
Form frmVeh = new vmsHome(conDB);
frmVeh.ShowDialog();
this.Close();
}
}//end try
catch(Exception ex)

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
4
by: Fred Flintstone | last post by:
This one baffles me. I'm using VS.Net 2005 and write desktop apps that need built in help. So logically, I figure maybe VS has a help system component built in so I search the help. Hey! ...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.