Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

TSQL to create Excel 2013 file Expand / Collapse
Author
Message
Posted Sunday, August 24, 2014 5:32 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, October 28, 2014 6:04 AM
Points: 1,127, Visits: 1,599
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.


Vinu Vijayan

For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden
Post #1606871
Posted Sunday, August 24, 2014 5:32 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 4:15 PM
Points: 6,842, Visits: 13,370
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
Post #1606872
Posted Sunday, August 24, 2014 5:37 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, October 28, 2014 6:04 AM
Points: 1,127, Visits: 1,599
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
Post #1606874
Posted Sunday, August 24, 2014 6:52 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 8:49 PM
Points: 2,420, Visits: 6,736
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.
Post #1606876
Posted Monday, August 25, 2014 9:00 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 6:04 AM
Points: 488, Visits: 1,993
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

Post #1607107
Posted Monday, August 25, 2014 10:46 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:08 PM
Points: 12,927, Visits: 32,333
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1607134
Posted Monday, August 25, 2014 11:25 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 8:49 PM
Points: 2,420, Visits: 6,736
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 enough
Post #1607146
Posted Sunday, August 31, 2014 11:57 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, October 28, 2014 6:04 AM
Points: 1,127, Visits: 1,599
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
Post #1609241
Posted Tuesday, September 2, 2014 9:39 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, October 28, 2014 6:04 AM
Points: 1,127, Visits: 1,599
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
Post #1609872
Posted Wednesday, September 3, 2014 1:08 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 6:22 AM
Points: 841, Visits: 1,474
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





Post #1609890
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse