My database is crupted

  • I need to do bulk copy any help on script for SQL 7 version.

  • One option would be to use Bulkcopy object of Sql DMO. If you need code sample let me know.

  • 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]

  • 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

  • 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.

  • 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.

  • 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.

  • <<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