excel connection string not working for excel 2007

Hello, I have the following excel connection string that works fine for excel version 97-2003 but does not work for excel version 2007:

Dim sExcelConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(sExcelFileName) & ";Extended Properties=""Excel 8.0;HDR=YES;IMEX=1"""

How can I modify my excel connection string to handle both excel versions?

           
gogetsomeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Look here for a reference:

http://www.connectionstrings.com/?carrier=excel2007

Example:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;Extended Properties="Excel 12.0;HDR=YES";

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gogetsomeAuthor Commented:
Thanks for the help. That should work for a 2007 document. I assume that the oledb12.0 and excel 12.0 are backward compatible with excel 97-2003 ?
0
Bob LearnedCommented:
No, the connection string that you showed in the question was the one for Excel 2003, and the 2007 connection string cannot be used for 2003.

Bob
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

gogetsomeAuthor Commented:
Ok, so I would first have to discover the excel type then use the appropriate string. Is there an easy way to do this?
0
Bob LearnedCommented:
One way to check for version is to look in the Windows registry for the appropriate key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0
   or
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0

Bob
0
gogetsomeAuthor Commented:
Thank for your help Bob. I will check that out. Have a great day!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.