Solved

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

Posted on 2004-08-30
4
223 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now