ok je commence :
j'excecute mon lot à partir de ma page aspx comme ça :
C'est juste pour info pour ceux que ça intéressse ^_^ mon problème est plus bas !!
j'utilise le code behind :
Protected Sub BtnMaj_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnMaj.Click
Dim oPkg, oStep, sMessage, bStatus
oPkg = Server.CreateObject(
"DTS.Package")
Const DTSSQLStgFlag_UseTrustedConnection = 256
oPkg.LoadFromSQLServer(
"SERVEUR", "", "", DTSSQLStgFlag_UseTrustedConnection, "", "", "", "Maj2")
oPkg.Execute()
bStatus =
True
For Each oStep In oPkg.Steps
If oStep.ExecutionResult = 1 Then
sMessage = sMessage &
"<p>" & "Step [" & oStep.Name & "] "
sMessage = sMessage &
" a termin<br>"
bStatus =
False
End If
Next
If bStatus Then
sMessage = sMessage &
"<p>Package [" & oPkg.Name & "] éxécuter avec succès</p>"
Else
sMessage = sMessage &
"<p>Package [" & oPkg.Name & "] a échoué.</p>"
End If
oStep =
Nothing
oPkg =
Nothing
LblReponse.Text = (sMessage)
End Subbon ça ça marche nickel !!
il faut au préalable créer son lot sur son serveur !
mon problème c'est que je voudrais passer en variable la source de ce lot :
j'ai donc enregitrer mon lot en vb.bas à partir de l'entreprise manager...
ça nous donne : après ajout des référence DTS :
Après correction trouver sur dtssql.com ça donne ça :
J'ai mis presque tous le code de mon lot mais je n'est que 3 erreurs écrite en très gros et en rouge et j'ai mis quelques commentaires en rouge également (j'espère ne pas être trop relou !!!)
Option
Explicit On ''A AJOUTER
Imports
DTS ''A AJOUTER
Imports
DTSPump ''pareil
Imports
DTSCustTasks '' la je suis pas sûr
Partial
Class param
Inherits System.Web.UI.Page
Private Sub Main()
dim goPackageOld As New DTS.Package
dim goPackage As DTS.Package2
goPackage = goPackageOld
goPackage.Name = "Maj2"
goPackage.Description =
"Description de lot DTS"
goPackage.WriteCompletionStatusToNTEventLog =
False
goPackage.FailOnError =
False
goPackage.PackagePriorityClass = 2
goPackage.MaxConcurrentSteps = 4
goPackage.LineageOptions = 0
goPackage.UseTransaction =
True
goPackage.TransactionIsolationLevel = 4096
goPackage.AutoCommitTransaction =
True
goPackage.RepositoryMetadataOptions = 0
goPackage.UseOLEDBServiceComponents =
True
goPackage.LogToSQLServer =
False
goPackage.LogServerFlags = 0
goPackage.FailPackageOnLogFailure =
False
goPackage.ExplicitGlobalVariables =
False
goPackage.PackageType = 0
Dim oConnProperty As DTS.OleDBProperty
'---------------------------------------------------------------------------
' create package connection information
'---------------------------------------------------------------------------
Dim oConnection As DTS.Connection2
'------------- a new connection defined below.
'For security purposes, the password is never scripted
'oConnection = goPackage.Connections.New(
"Microsoft.Jet.OLEDB.4.0")
'oConnection.ConnectionProperties("Data Source") = '"C:\Inetpub\wwwroot\upload\Maj.xls" ''c'est ça que je veux en variable !!!!
''Sinon il vient le chercher aux même endroit sur le client!!!
oConnection.ConnectionProperties(
"Extended Properties") = "Excel 8.0;HDR=YES;"
''CODE QU'IL FAUT D'AILLEUR MODIFIER EN :
oConnection.ConnectionProperties.item("Data Source") .value= "C:\Inetpub\wwwroot\upload\Maj.xls"
oConnection.ConnectionProperties.item(
"Extended Properties").value = "Excel 8.0;HDR=YES;"
oConnection.Name =
"Connexion 1"
oConnection.ID = 1
oConnection.Reusable =
True
oConnection.ConnectImmediate =
False
oConnection.DataSource =
"C:\Inetpub\wwwroot\upload\Maj.xls"
oConnection.ConnectionTimeout = 60
oConnection.UseTrustedConnection =
False
oConnection.UseDSL =
False
'If you have a password for this connection, please uncomment and add your password below.
'oConnection.Password = "<put the password here>"
goPackage.Connections.Add(oConnection)
oConnection =
Nothing
'------------- a new connection defined below.
'For security purposes, the password is never scripted
oConnection = goPackage.Connections.New(
"SQLOLEDB")
oConnection.ConnectionProperties.Item(
"Integrated Security").Value = "SSPI"
oConnection.ConnectionProperties.Item(
"Persist Security Info").Value = True
oConnection.ConnectionProperties.Item(
"Initial Catalog").Value = "Bd"
oConnection.ConnectionProperties.Item(
"Data Source").Value = "SERVEUR"
oConnection.ConnectionProperties.Item(
"Application Name").Value = "Assistant Importation/exportation DTS (Data Transformation Services)"
oConnection.Name =
"Connexion 2"
oConnection.ID = 2
oConnection.Reusable =
True
oConnection.ConnectImmediate =
False
oConnection.DataSource =
"SERVEUR"
oConnection.ConnectionTimeout = 60
oConnection.Catalog =
"exclus"
oConnection.UseTrustedConnection =
True
oConnection.UseDSL =
False
'If you have a password for this connection, please uncomment and add your password below.
'oConnection.Password = "<put the password here>"
goPackage.Connections.Add(oConnection)
oConnection =
Nothing
'---------------------------------------------------------------------------
' create package steps information
'---------------------------------------------------------------------------
Dim oStep As DTS.Step2
Dim oPrecConstraint As DTS.PrecedenceConstraint
'------------- a new step defined below
oStep = goPackage.Steps.New
oStep.Name =
"Copy Data from Feuil1$ to [Bd].[dbo].[Bd] étape"
oStep.Description =
"Copy Data from Feuil1$ to [Bd].[dbo].[Bd] étape"
oStep.ExecutionStatus = 1
oStep.TaskName =
"Copy Data from Feuil1$ to [Bd].[dbo].[Bd] Tâche"
oStep.CommitSuccess =
False
oStep.RollbackFailure =
False
oStep.ScriptLanguage =
"VBScript"
oStep.AddGlobalVariables =
True
oStep.RelativePriority = 3
oStep.CloseConnection =
False
oStep.ExecuteInMainThread =
True
oStep.IsPackageDSORowset =
False
oStep.JoinTransactionIfPresent =
False
oStep.DisableStep =
False
oStep.FailPackageOnError =
False
goPackage.Steps.Add(oStep)
oStep =
Nothing
'---------------------------------------------------------------------------
' create package tasks information
'---------------------------------------------------------------------------
'------------- call Task_Sub1 for task Copy Data from Feuil1$ to [exclus].[dbo].[exclus] Tche (Copy Data from Feuil1$ to [exclus].[dbo].[exclus] Tche)
Call Task_Sub1(goPackage)
'---------------------------------------------------------------------------
' Save or execute package
'---------------------------------------------------------------------------
'goPackage.SaveToSQLServer "(local)", "sa", ""
goPackage.Execute()
tracePackageError(goPackage)
goPackage.Uninitialize()
'to save a package instead of executing it, comment out the executing package line above and uncomment the saving package line
goPackage =
Nothing
goPackageOld =
Nothing
End Sub
'-----------------------------------------------------------------------------
' error reporting using step.GetExecutionErrorInfo after execution
'-----------------------------------------------------------------------------
Public Sub tracePackageError(ByVal oPackage As DTS.Package)
Dim ErrorCode As Long
Dim ErrorSource As String
Dim ErrorDescription As String
Dim ErrorHelpFile As String
Dim ErrorHelpContext As Long
Dim ErrorIDofInterfaceWithError As String
Dim i As Integer
For i = 1 To oPackage.Steps.Count
If oPackage.Steps(i).ExecutionResult = DTSStepExecResult_Failure Then
''L'interface DTS Step ne peut être indexé !!!
oPackage.Steps(i).GetExecutionErrorInfo(ErrorCode, ErrorSource, ErrorDescription, _
ErrorHelpFile, ErrorHelpContext, ErrorIDofInterfaceWithError)
MsgBox(oPackage.Steps(i).Name &
" failed" & vbCrLf & ErrorSource & vbCrLf & ErrorDescription)
End If
Next i
End Sub
'------------- define Task_Sub1 for task Copy Data from Feuil1$ to [exclus].[dbo].[exclus] Tche (Copy Data from Feuil1$ to [exclus].[dbo].[exclus] Tche)
Public Sub Task_Sub1(ByVal goPackage As Object)
Dim oTask As DTS.Task
Dim oLookup As DTS.Lookup
Dim oCustomTask1 As DTS.DataPumpTask2
oTask = goPackage.Tasks.New(
"DTSDataPumpTask")
'' un appel à un constructeur est valide uniquement en tant que ''première instruction dans un constructeur d'instance
oTask.Name =
"Copy Data from Feuil1$ to [Bd].[dbo].[Bd] Tâche"
oCustomTask1 = oTask.CustomTask
oCustomTask1.Name =
"Copy Data from Feuil1$ to [Bd].[dbo].[Bd] Tâche"
oCustomTask1.Description =
"Copy Data from Feuil1$ to [Bd].[dbo].[Bd] Tâche"
oCustomTask1.SourceConnectionID = 1
oCustomTask1.SourceSQLStatement =
"select `nom`,`prenom`,`surnom`,`dn........ from `Feuil1$`"
oCustomTask1.DestinationConnectionID = 2
oCustomTask1.DestinationObjectName =
"[exclus].[dbo].[exclus]"
oCustomTask1.ProgressRowCount = 1000
oCustomTask1.MaximumErrorCount = 0
oCustomTask1.FetchBufferSize = 1
oCustomTask1.UseFastLoad =
True
oCustomTask1.InsertCommitSize = 0
oCustomTask1.ExceptionFileColumnDelimiter =
"|"
oCustomTask1.ExceptionFileRowDelimiter = vbCrLf
oCustomTask1.AllowIdentityInserts =
False
oCustomTask1.FirstRow = 0
oCustomTask1.LastRow = 0
oCustomTask1.FastLoadOptions = 2
oCustomTask1.ExceptionFileOptions = 1
oCustomTask1.DataPumpOptions = 0
Call oCustomTask1_Trans_Sub1(oCustomTask1)
goPackage.Tasks.Add(oTask)
oCustomTask1 =
Nothing
oTask =
Nothing
End Sub
Public Sub oCustomTask1_Trans_Sub1(ByVal oCustomTask1 As Object)
Dim oTransformation As DTS.Transformation2
Dim oTransProps As DTS.Properties
Dim oColumn As DTS.Column
oTransformation = oCustomTask1.Transformations.New(
"DTS.DataPumpTransformCopy")
'' un appel à un constructeur est valide uniquement en tant que ''première instruction dans un constructeur d'instance
oTransformation.Name =
"DirectCopyXform"
oTransformation.TransformFlags = 63
oTransformation.ForceSourceBlobsBuffered = 0
oTransformation.ForceBlobsInMemory =
False
oTransformation.InMemoryBlobSize = 1048576
oTransformation.TransformPhases = 4
oColumn = oTransformation.SourceColumns.New(
"nom", 1)
Le reste il est Content !!!