exportdata avec dmo

exportdata avec dmo - SQL/NoSQL - Programmation

Marsh Posté le 20-03-2004 à 19:05:11    

Bonjour,
je souhaite exporter les données d'une table sqlserver (en local) avec un script vbs. J'ai récupéré un script mais j'ai toujours la meme erreur (object required à la ligne exportdata).
Voila le code (pourtant tres simple), si vous avez une idée?? :
 
Dim oServer
Dim oDatabase
Dim oBCP
Dim nRows
dim table
 
dim oTable  
dim sResults
 
 
on error resume next
 
if WScript.Arguments(0) = "" then
      WScript.Echo "Vous n'avez pas spécifié de base de données à laquelle se connecter."
      WScript.Quit
end if
 
 
Set oServer = CreateObject("SQLDMO.SQLServer" )
oServer.LoginSecure = True  
   
Set oBCP = CreateObject("SQLDMO.BulkCopy" )
 
oServer.EnableBcp = True
 
oServer.Connect "." ', "sa"  
 
Set oDatabase = oServer.Databases(Wscript.Arguments(0))
msgbox oDatabase.SpaceAvailableInMB
 
 
For Each oDatabase In oServer.Databases  
For Each oTable In oDatabase.Tables
    if oTable.systemobject = false then
     sResults = sResults & oTable.Name & Chr(13) & Chr(10)
    end if
Next  
msgbox sResults
Next
 
 
oBCP.ColumnDelimiter = vbComma
oBCP.DataFileType = SQLDMODataFile_CommaDelimitedChar
oBCP.ImportRowsPerBatch = 1000
oBCP.MaximumErrorsBeforeAbort = 1
BCP.RowDelimiter = vbCrLf
oBCP.ServerBCPDataFileType = SQLDMOBCPDataFile_Char
oBCP.UseExistingconnection = True
 
if wscript.Arguments(1) = "" then
      for each table in oDatabase.tables
            ' pas une table systeme
            if table.systemobject = false then
                  oBCP.DataFilePath = table.name & ".csv"
                  nRows = table.ExportData(oBCP)
                  wscript.Echo nRows & " lignes exportées à partir de " & table.name
            end if
      next
else
      oBCP.DataFilePath = wscript.Arguments(1) & ".csv"  
      nRows = oDatabase.Tables(wscript.arguments(1)).ExportData(oBCP)
      wscript.Echo nRows & " lignes exportées à partir de " & wscript.arguments(1)
end if

 
merci pour votre aide :)  

Reply

Marsh Posté le 20-03-2004 à 19:05:11   

Reply

Marsh Posté le 20-03-2004 à 19:06:02    

mince excusez moi pour la couleur du code

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed