sridhar79
asked on
COMException while opening excel file
Hi,
I am trying to open an excel file using .NET's excel object. It was working fine before.. I dont know why it started giving me a COMException error recently.. I am trying to figure why but I cant.. My excel is not protected or locked.. But still it gives me the same error. This is what I coded:
Dim strcon As String
strcon = "PROVIDER = Microsoft.jet.OLEDB.4.0; Data Source = " & _
Me.txtTemplateFile.Text & "; Extended Properties = Excel 8.0 "
Dim olecon As OleDb.OleDbConnection
olecon = New OleDb.OleDbConnection(strc on)
olecon.Open()
Dim table As DataTable
Dim objxl As Excel.Application
objxl = New Excel.Application()
Dim wbxs As Excel.Workbooks
Dim wbxl As Excel.Workbook
Dim xl_file As String
xl_file = Me.txtTemplateFile.Text
wbxs = objxl.Workbooks
wbxl = wbxs.Add
wbxl = wbxs.Open(xl_file)
and this is the error it generates
An unhandled exception of type 'System.Runtime.InteropSer vices.COME xception' occurred in WindowsApplication2.exe
Additional information: Cannot access 'Lab_Data_Sheet.xls'.
Any comments or suggestions would be greatly appreciated.
Thanks,
Yash
I am trying to open an excel file using .NET's excel object. It was working fine before.. I dont know why it started giving me a COMException error recently.. I am trying to figure why but I cant.. My excel is not protected or locked.. But still it gives me the same error. This is what I coded:
Dim strcon As String
strcon = "PROVIDER = Microsoft.jet.OLEDB.4.0; Data Source = " & _
Me.txtTemplateFile.Text & "; Extended Properties = Excel 8.0 "
Dim olecon As OleDb.OleDbConnection
olecon = New OleDb.OleDbConnection(strc
olecon.Open()
Dim table As DataTable
Dim objxl As Excel.Application
objxl = New Excel.Application()
Dim wbxs As Excel.Workbooks
Dim wbxl As Excel.Workbook
Dim xl_file As String
xl_file = Me.txtTemplateFile.Text
wbxs = objxl.Workbooks
wbxl = wbxs.Add
wbxl = wbxs.Open(xl_file)
and this is the error it generates
An unhandled exception of type 'System.Runtime.InteropSer
Additional information: Cannot access 'Lab_Data_Sheet.xls'.
Any comments or suggestions would be greatly appreciated.
Thanks,
Yash
ASKER
CJ,
I tried putting fully qualified path but it still gives me the same error. I tried to catch the exception it gave me the following:
Unhandled Exception: System.Runtime.InteropServ ices.COMEx ception (0x800A03EC): Cannot access 'Lab_Data_Sheet.xls'.
at Excel.Workbooks.Open(Strin g Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru)
Can you figure out the glitch from this detailed error catch?
Thanks,
Yash
I tried putting fully qualified path but it still gives me the same error. I tried to catch the exception it gave me the following:
Unhandled Exception: System.Runtime.InteropServ
at Excel.Workbooks.Open(Strin
Can you figure out the glitch from this detailed error catch?
Thanks,
Yash
ASKER
It was working fine last week as I was opening another xls file and reading the data from it. Now even that file is not being read. I could not go into the event viewer as I dont have enough admin rights. I checked the security settings and not even a single xls file has protection on it.. It is kind of confusing for me.. Any suggestions??
Yash
Yash
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
I figured out the glitch. As you can see from the code I was trying to open the file which already got open using oledb. It wasn't opening as it was already open. Thanks for your suggestions anyway..
I figured out the glitch. As you can see from the code I was trying to open the file which already got open using oledb. It wasn't opening as it was already open. Thanks for your suggestions anyway..
Last thing to check is the event viewer, it may have some more details for you!
CJ