473,396 Members | 2,111 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,396 software developers and data experts.

Process EXCEL.exe never close ! Help please

Hello,

I've got a problem on my last code made for take data on SQL and put it on a specific worksheet in Excel.

The process Excel.exe is never close !

Any idea please ?

Expand|Select|Wrap|Line Numbers
  1. Module Module1
  2.  
  3.     Sub Main()
  4.  
  5.         Dim xlApp As New xls.Application
  6.         Dim xlBook As xls.Workbook
  7.         Dim xlSheet As xls.Worksheet
  8.  
  9.         Dim Connexion As New SqlConnection("Data Source=localhost;Initial Catalog=bdd_name;User Id=sa;Password=159753;")
  10.         Dim Requete As String = "SELECT * FROM Table_test"
  11.  
  12.         xlBook = xlApp.Workbooks.Open("C:\Users\toto\Desktop\Classeur1.xlsx")
  13.         xlSheet = xlBook.Worksheets("test")
  14.  
  15.         'Connexion à la BDD
  16.         Connexion.Open()
  17.  
  18.         Dim Commande As New SqlCommand(Requete, Connexion)
  19.         Dim Adaptateur As New SqlDataAdapter(Commande)
  20.         Dim MonDataSet As New DataSet
  21.  
  22.         Try
  23.             Adaptateur.Fill(MonDataSet, "test")
  24.         Catch ex As Exception
  25.  
  26.             Console.WriteLine(ex.Message)
  27.             Commande.Dispose()
  28.             Connexion.Close()
  29.         End Try
  30.  
  31.         Commande.Dispose()
  32.         Connexion.Close()
  33.  
  34.         Dim RowInd As Int16 = 1
  35.         Dim ColInd As Int16 = 1
  36.  
  37.         xlSheet.Range("A1", "Z5000").Value = ""
  38.  
  39.         For ColInd = 0 To 4
  40.             For Each Ligne As DataRow In MonDataSet.Tables("Alarms").Rows()
  41.                 xlSheet.Cells(RowInd, ColInd + 1).Value = Ligne(ColInd).ToString
  42.                 RowInd += 1
  43.             Next
  44.             RowInd = 1
  45.         Next
  46.  
  47.         xlApp.DisplayAlerts = False
  48.         xlSheet.SaveAs("C:\Users\toto\Desktop\Classeur1.xlsx")
  49.         xlBook.Close(False)
  50.         xlApp.Quit()
  51.         xlApp.DisplayAlerts = True
  52.  
  53.         ReleaseObject(xlApp)
  54.         ReleaseObject(xlBook)
  55.         ReleaseObject(xlSheet)
  56.  
  57.         xlApp = Nothing
  58.         xlBook = Nothing
  59.         xlSheet = Nothing
  60.     End Sub
  61.  
  62.  
  63.     Private Sub ReleaseObject(ByVal obj As Object)
  64.         Try
  65.             System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
  66.             obj = Nothing
  67.         Catch ex As Exception
  68.             obj = Nothing
  69.         Finally
  70.             GC.Collect()
  71.         End Try
  72.     End Sub
  73. End Module
Feb 5 '16 #1
1 1326
madankarmukta
308 256MB
You hav to release each RCW object you hav created using marshal.releasecomobject.

Hope this helps.
Feb 9 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ronny Sigo | last post by:
Hello all, I have to open a readonly Excel sheet from clicking on a button on an access form. So far no problem: Dim ObjXL As Excel.Application Dim ObjXLBook As Excel.Workbook Dim ObjXLSheet As...
9
by: AA | last post by:
This is making me crazy!! Please, if some body can help me. I'm testing a ver simple socket client. In my test I just open and close a connection (in a loop) to my local IIS server (port 80)...
2
by: Luther Miller | last post by:
I have a server setup that is dedicate to providing a "proxy" by exposing a web service that calls methods in a 3rd party ActiveX control and then returns the results. Sometimes, the aspnet_wp work...
5
by: mwazir | last post by:
Dear all, I have a .NET app that processes some excel file and it was working in all scenarios. Recently however we received excel files from a new client which my application has been unable...
11
by: Nurit N | last post by:
This is the third newsgroup that I'm posting my problem. I'm sorry for the multiple posts but the matter becoming urgent. I hope this is the right place for it... I have created a very...
2
by: Jason Huang | last post by:
Hi, In my C# windows form application, we can open and close an EXCEL file. However, in my Windows XP's task manager, there is a EXCEL on the task list. If I open and close that EXCEL file...
2
by: coala | last post by:
My visual studio crashes when I attach to a process (i.e. Excel) so I cannot debug. Would anyone have any advice on what I can do/I am doing wrong please? I have installed all the latest...
2
by: =?Utf-8?B?TEJU?= | last post by:
Good Day, I have a web application created using ASP.NET (with VB.NET). The application allow user to browse Excel raw data file then the program will grab data from the file to perform further...
1
by: popsoftheyear | last post by:
I'm trying to automate some very simple things in excel, but have run into a roadblock (using c++). To detect excel closing, I just monitor the Excel Process using WaitForSingleObject. In order to...
1
by: raul15791 | last post by:
Hi, I'm new to C#. I'm writing a program that open a new excel file, write into it and lastly close the file. But the program is that there will be a orphaned process named EXCEL.EXE left on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.