sql server - Need help to execute SQL in text file with SQLCMD -


i want load excel file (.xls) table in database. database on own computer , have sa account in sql server 08. excel file contains -

id  name 1   dog 2   cat 3   fish 

the file (demo.txt) sql code:

insert [mydb].[dbo].[relative]     select *      openrowset('microsoft.jet.oledb.4.0','excel 8.0;                    database=c:\my temp files\excel','select * [sheet1$]'); 

the sqlcmd code:

sqlcmd -s mypc\sql2008 -i "c:\my temp files\sql\demo.txt" 

the error in sqlcmd:

msg 7308, level 16, state 1, server mypc\sql2008, line 1
ole db provider 'microsoft.jet.oledb.4.0' cannot used distributed queries because provider configured run in single-threaded apartment mode.

a fix (which not solve problem) above error http://blog.sqlauthority.com/2010/11/03/sql-server-fix-error-ms-jet-oledb-4-0-cannot-be-used-for-distributed-queries-because-the-provider-is-used-to-run-in-apartment-mode/

sp_configure 'show advanced options', 1; go reconfigure; go sp_configure 'ad hoc distributed queries', 1; go reconfigure; go 

how fix thing , make work ?


edits -


i tried stuff in comments of above link , got error -

msg 7399, level 16, state 1, server mypc\sql2008, line 1 ole db provider "microsoft.ace.oledb.12.0" linked server "(null)" report ed error. provider did not give information error. msg 7303, level 16, state 1, server mypc\sql2008, line 1 cannot initialize data source object of ole db provider "microsoft.ace.oledb .12.0" linked server "(null)". 

what tried -

download , install new 64 bit component microsoft: http://www.microsoft.com/downloads/en/details.aspx?familyid=c06b8369-60dd-4b64-a44b-84b371ede16d&displaylang=en

to install above component, there no need uninstall 32bit office apps first. can install 64-bit microsoft access database engine 2010 redistributable components using command prompt.

c:\downloads\accessdatabaseengine_x64.exe /passive 

open sql server , run following:

sp_configure 'show advanced options', 1; go reconfigure; go sp_configure 'ad hoc distributed queries', 1; go reconfigure; go  exec master.dbo.sp_msset_oledb_prop n'microsoft.ace.oledb.12.0',  n'allowinprocess', 1 go exec master.dbo.sp_msset_oledb_prop n'microsoft.ace.oledb.12.0',  n'dynamicparameters', 1 go 

this sets parameters needed access , run queries related components. address ‘null

now, if running openrowset calls need abandon calls, made using old jet parameters , use new calls follows:

(*example, importing excel file directly sql):

dont this…

select * openrowset('microsoft.jet.oledb.4.0','excel 8.0;hdr=yes; database=c:\path_to_your_exexcel_file.xls', 'select * [sheet1$]') 

use instead…

select * openrowset('microsoft.ace.oledb.12.0', 'excel 12.0; database=c:\path_to_your_exexcel_file.xls','select * [sheet1$]') 

now, how fix error new approach gave me ?


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -