Solved

Export data from MS-SQL 8.0 to text without using bcp or xp_cmdshell

Posted on 2004-08-30
4
231 Views
Last Modified: 2008-01-09
How ?
I did succeed to import with bulk insert from ...
but I need to process that data and do the export by rewriting the text file as well.

Thanks.
Gregor
0
Comment
Question by:gregajesih
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:arbert
ID: 11930890
You can always use DTS and the sp_OA stored procedures to call it...
0
 
LVL 34

Accepted Solution

by:
arbert earned 250 total points
ID: 11930915
(there is an example of SP_OA here--scroll down past the xp_cmdshell example http://www.databasejournal.com/features/mssql/article.php/1459181)

Brett
0
 

Author Comment

by:gregajesih
ID: 11939292
It seems there is nothing better (more elegant and simpler) then I accept the answer.
Thank you.
0
 

Author Comment

by:gregajesih
ID: 11942415
Well, I tried the approach and it seems that something is still not working.
I used this code with query analyzer being connected to the server and database where the source data is present and DTS package is stored in the same server under "ThisServer-DTS-Local packages".

MS-SQL Code:

-- create package
declare @hr int
declare @oPKG int
EXEC @hr = sp_OACreate 'DTS.Package', @oPKG OUT
IF @hr <> 0
BEGIN
    PRINT '***  Create Package object failed'
    EXEC sp_displayoaerrorinfo @oPKG, @hr
    RETURN
END

--Loading the Package:
-- DTSSQLServerStorageFlags :
--- DTSSQLStgFlag_Default = 0
--- DTSSQLStgFlag_UseTrustedConnection = 256
--EXEC @hr = sp_OAMethod @oPKG,
--  'LoadFromSQLServer("localhost","","", 256, , , , "ExportBsnprof",)',
--  NULL
EXEC @hr = sp_OAMethod @oPKG, 'LoadFromSqlServer', NULL,
  @ServerName='10.100.10.30\MPSCENTER', @ServerUsername='usernametext', @ServerPassword='passwordtext',@PackageName='ExportBsnprof', @Flags=256

IF @hr <> 0
BEGIN
    PRINT '***  Load Package failed'
    EXEC sp_displayoaerrorinfo @oPKG, @hr
    RETURN
END

--Executing the Package:
EXEC @hr = sp_OAMethod @oPKG, 'Execute'
IF @hr <> 0
BEGIN
    PRINT '***  Execute failed'
    EXEC sp_displayoaerrorinfo @oPKG , @hr
    RETURN
END
else
    print 'Executed!'

--Cleaning up:
EXEC @hr = sp_OADestroy @oPKG
IF @hr <> 0
BEGIN
    PRINT '***  Destroy Package failed'
    EXEC sp_displayoaerrorinfo @oPKG, @hr
    RETURN
END

..and here is the result grid text:

/*-----------------------------

-- create package
declare @hr int
-----------------------------*/
Executed!
 
What's wrong ?
Thanks.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
LTrim & Double Space Correction 5 40
t-sql need help on t-sql 10 25
SQL Backup Question 2 29
SQL Server Configuration Manager WMI Error 11 17
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question