tags:

views:

39

answers:

3
IF @hr=0 
EXEC @hr=sp_OACreate 'Excel.Application', @objExcel OUT

The above line for creating excel is giving errorcode "-2147221005"

+2  A: 

You're trying to create the COM object for Excel on your SQL Server and it fails.

Do you really have the Microsoft Office package installed on your SQL Server?? Normally, this is not considered a good idea.... (at least on a production server).

If I were you, I'd try to find another way to generate a file that Excel can use - e.g. a CSV file or something like that.

For a few ideas, see:

marc_s
+1, Excel on server is a really really **BAD** idea.
Rubens Farias
A: 

Maybe you do not have Excel installed on the Sql server box.

You should rather try using a different approach

See

EDIT for Comment:

Maybe this would be best handled by the Application layer, and let Sql Server do what it does best.

astander
The Out put excel should contain formulas and user can change values depedns on that it should calculate values of other cells with the formula for ex =SUMPRODUCT(C7:E7,C11:E11).
Nag
+2  A: 

This kind of processing does not belong in a SQL clr procedure. Do it in the client, using the Primary Interop Assemblies of Office, see How to automate Microsoft Excel from Microsoft Visual C# .NET. If you insist on doing it from the server, your SQL Server instance may unexpectedly vanish.

Remus Rusanu