SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


TSQL to create Excel 2013 file


TSQL to create Excel 2013 file

Author
Message
vinu512
vinu512
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1693 Visits: 1625
Permissions don't seem to be the issue either. I am doin this on my laptop. There is only one user on my laptop. So, permissions are also fine.

Please help guys. This is makin me rip off my hair. CrazySickCrazy

Vinu Vijayan

For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden ;-)
LutzM
LutzM
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10453 Visits: 13559
What permission does the user have who's running that code?

Based on MS Technet
Only members of the sysadmin fixed server role can execute sp_OASetProperty.

If you're not a member of the sysadmin role, this might be the reason for not creating the file.



Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
vinu512
vinu512
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1693 Visits: 1625
LutzM (8/24/2014)
What permission does the user have who's running that code?

Based on MS Technet
Only members of the sysadmin fixed server role can execute sp_OASetProperty.

If you're not a member of the sysadmin role, this might be the reason for not creating the file.


As I mentioned earlier, I am using the admin account on my Lappy.
And I am logged into sql server using Windows Authentication.
And I do have the sys admin role checked for this login.

Vinu Vijayan

For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden ;-)
Eirikur Eiriksson
Eirikur Eiriksson
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15328 Visits: 18612
vinu512 (8/24/2014)
LutzM (8/24/2014)
What permission does the user have who's running that code?

Based on MS Technet
Only members of the sysadmin fixed server role can execute sp_OASetProperty.

If you're not a member of the sysadmin role, this might be the reason for not creating the file.


As I mentioned earlier, I am using the admin account on my Lappy.
And I am logged into sql server using Windows Authentication.
And I do have the sys admin role checked for this login.


This is not a question about your credentials on the box but the SQL server's, don't think that process is running as admin.
Cool
sqldriver
sqldriver
SSC Eights!
SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)

Group: General Forum Members
Points: 982 Visits: 2518
Just a thought, if you can't get the permissions for the SQL Service account sorted out. You can always raise makewebtask from the dead, if you still have a 2008 instance with the .dll sitting around somewhere:


--EXEC dbo.sp_addextendedproc N'xp_makewebtask', 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\xpweb90.dll'
--EXECUTE master..xp_makewebtask


Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28480 Visits: 39970
correct me if i'm wrong, but I thought noone can write to a file on the root of the C drive unless they are running elevated, admin priviledges:

so C:\CambridgePubs.xlsx would fail, but
C:\Data\CambridgePubs.xlsx would probably be ok, assuming path/file exists and all that stuff.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Eirikur Eiriksson
Eirikur Eiriksson
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15328 Visits: 18612
Lowell (8/25/2014)
correct me if i'm wrong, but I thought noone can write to a file on the root of the C drive unless they are running elevated, admin priviledges:

so C:\CambridgePubs.xlsx would fail, but
C:\Data\CambridgePubs.xlsx would probably be ok, assuming path/file exists and all that stuff.


My point exactly! Maybe I didn't communicate it well enoughErmm
Cool
vinu512
vinu512
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1693 Visits: 1625
Lowell (8/25/2014)
correct me if i'm wrong, but I thought noone can write to a file on the root of the C drive unless they are running elevated, admin priviledges:

so C:\CambridgePubs.xlsx would fail, but
C:\Data\CambridgePubs.xlsx would probably be ok, assuming path/file exists and all that stuff.


True. But it doesn't work even if I change the path to D drive.
Sorry for the late reply, was on a work trip and didnt get time for this.

Any other ideas guys?

Vinu Vijayan

For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden ;-)
vinu512
vinu512
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1693 Visits: 1625
Does this work for anyone??....Can someone please test the code on your local box and let me know??...Thanks

Vinu Vijayan

For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden ;-)
twin.devil
twin.devil
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2397 Visits: 2675
i have just added the error message generation in your code. try to execute it and check what error its generate


DECLARE @objExcel INT,@hr INT,@command VARCHAR(255),@strErrorMessage VARCHAR(255),@objErrorObject INT,@objConnection INT,@bucket INT,
@DDL VARCHAR(2000),@DataSource VARCHAR(100),@Worksheet VARCHAR(100)=NULL,@ConnectionString VARCHAR(255), @document int

Select @ConnectionString = 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%DataSource;Extended Properties="Excel 12.0 XML;HDR=YES"',
@DDL='Create table CambridgePubs(Pubname Text, Address Text, Postcode Text)',
@DataSource ='C:\CambridgePubs.xlsx'

SELECT @ConnectionString = REPLACE (@ConnectionString, '%DataSource', @DataSource)
print @ConnectionString
EXEC @hr = sp_OACreate 'ADODB.Connection', @objconnection OUT
print @hr
EXEC @hr=sp_OASetProperty @objconnection,'ConnectionString', @ConnectionString
print @hr
print @objconnection

EXEC @hr=sp_OAMethod @objconnection, 'Open'
print @hr
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @objconnection
Return
END;
EXEC @hr=sp_OAMethod @objconnection, 'Execute',@Bucket out , @DDL
print @hr
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @objconnection
Return
END;



If the error is something like this

0x800A0E7A ADODB.Connection Provider cannot be found. It may not be properly installed.


Then i believe you are 64bit SQL SERVER, with 32 bit access driver you need a 64bit driver.

Download "AccessDatabaseEngine_X64.exe" from http://www.microsoft.com/en-gb/download/details.aspx?id=13255
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search