Solved

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

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

947 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

20 Experts available now in Live!

Get 1:1 Help Now