April 15, 2003 at 11:03 am
I need to do bulk copy any help on script for SQL 7 version.
April 15, 2003 at 11:14 am
One option would be to use Bulkcopy object of Sql DMO. If you need code sample let me know.
April 15, 2003 at 11:25 am
That will be great. Thanks.
One option would be to use Bulkcopy object of Sql DMO. If you need code sample let me know.
[/quote]
April 15, 2003 at 11:40 am
Dim usrServer As SQLDMO.SQLServer
Dim usrBcp As SQLDMO.BulkCopy
Dim lngRowsImported As Long
Set usrServer = New SQLDMO.SQLServer
usrServer.Connect "<SERVER>", "<USER>", "<PASSWORD>"
Set usrBcp = New SQLDMO.BulkCopy
With usrBcp
.DataFilePath = "TextFile.Txt"
.ErrorFilePath = "TextFile.Err"
.LogFilePath = "TextFile.log"
.DataFileType = SQLDMODataFile_SpecialDelimitedChar
.RowDelimiter = vbNewLine
.ColumnDelimiter = ","
.ImportRowsPerBatch = 500
.MaximumErrorsBeforeAbort = 100
End With
lngRowsImported = usrServer.Databases("<DBNAME>").Tables("<TABLNAME>").ImportData(usrBcp)
---------------------------------------------
Note that this is fully customizable. You can change the options depending on the text file format. Currently this assumes that it uses , as field separator and newline character as row separator.
---------------------------------------------
Hope this helps
April 15, 2003 at 11:51 am
Thanks for your help. I have follwoing question.
lngRowsImported = usrServer.Databases("<DBNAME>").Tables("<TABLNAME>").ImportData(usrBcp)
Will this work for all the tables and objects in the database?
Thanks.
April 15, 2003 at 11:58 am
Sorry I forgot to mention.
No it will not work for generic tables.
You need to replace <SERVER> <DBNAME> <USER> <PASSWORD> and <TABLENAME> with the values specific to your environment.
April 15, 2003 at 12:05 pm
So i have this will work for each table at a time?
So if i have 200 tables I need to run this 200 time?
Thanks.
April 16, 2003 at 12:49 am
<<So if i have 200 tables I need to run this 200 time?>>
Yes. This works one table at a time.
If you have 200 tables then you need to have 200 text files also(one for each table).
However you can write code to loop through each table in the Tables collection.
-----------------------------------------
For each usrTable in usrServer.Databases("<DBNAME>").Tables
Set the parameters for usrBcp
usrTable.Importdata(usrBcp)
Next
-----------------------------------------
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply