Click here to Skip to main content
15,892,697 members
Home / Discussions / C#
   

C#

 
GeneralRe: WebService problem Pin
leppie8-Aug-05 4:12
leppie8-Aug-05 4:12 
GeneralRe: WebService problem Pin
Dario Solera8-Aug-05 4:15
Dario Solera8-Aug-05 4:15 
GeneralComboBox Pin
zaboboa8-Aug-05 3:11
zaboboa8-Aug-05 3:11 
GeneralRe: ComboBox Pin
Alomgir Miah8-Aug-05 3:23
Alomgir Miah8-Aug-05 3:23 
GeneralRe: ComboBox Pin
zaboboa8-Aug-05 3:25
zaboboa8-Aug-05 3:25 
GeneralRe: ComboBox Pin
Alomgir Miah8-Aug-05 4:02
Alomgir Miah8-Aug-05 4:02 
GeneralRe: ComboBox Pin
Mohamad Al Husseiny8-Aug-05 4:05
Mohamad Al Husseiny8-Aug-05 4:05 
GeneralCreating DTS Packages in C# Pin
JMichael24688-Aug-05 3:05
JMichael24688-Aug-05 3:05 
I am trying to create a DTS package using C#. I have done this in VB6 without any problems. However, when I convert everything over to C# I
get the 'System.InvalidCastException'. I am running windows 2000, SQL
2000 sp3a. I have also followed the instructions in using DTS provided


by "http://sqldev.net/DTS/dotnetcookbook.htm".


The error is occurs at this line:

<br />
DTS.DataPumpTask DT = (DTS.DataPumpTask)package.Task­­s.New <br />
("DTSDataPumpTask"); <br />



Does anyone know what causes this and is there a fix for it?


Below is a copy of the code.

<br />
public void createPackag() <br />
                { <br />
                        DTS.Connection oConnection = <br />
(DTS.Connection)package.Connec­­tions.New("Microsoft.Jet.OLED­B­.4.0"); <br />
<br />
<br />
                        oConnection.Name ="Connection 1"; <br />
                        oConnection.DataSource = "C:\\MySourceDB.MDB"; <br />
                        oConnection.ID = 1; <br />
                        oConnection.Reusable = true; <br />
                        oConnection.ConnectImmediate = false; <br />
                        oConnection.ConnectionTimeout = 60; <br />
                        oConnection.UseTrustedConnecti­­on = false; <br />
                        oConnection.UseDSL = false; <br />
                        oConnection = null; <br />
                        DTS.Connection oConnection2 = <br />
(DTS.Connection)package.Connec­­tions.New("SQLOLEDB"); <br />
                        oConnection2.Name = "Connection 2"; <br />
                        oConnection2.ID = 2; <br />
                        oConnection2.Reusable = true; <br />
                        oConnection2.ConnectImmediate= false; <br />
                        oConnection2.DataSource= "MyServerName"; <br />
                        oConnection2.UserID = "MyUserID"; <br />
                        oConnection2.ConnectionTimeout = 60; <br />
                        oConnection2.Catalog =  "MyDestDB"; <br />
                        oConnection2.UseTrustedConnect­­ion = false; <br />
                        oConnection2.UseDSL = false; <br />
                        oConnection2.Password = "MyPassword"; <br />
                        oConnection2 = null; <br />
                        DTS.Step2 oStep = <br />
(DTS.Step2)package.Steps.New()­­; <br />
                        oStep.Name = "Copying Data from MyTable"; <br />
                        oStep.Description = "Copying Data from <br />
MyTable"; <br />
                        oStep.TaskName = "Copying Data from MyTable"; <br />
                        oStep.CommitSuccess = false; <br />
                        oStep.RollbackFailure = false; <br />
                        oStep.ScriptLanguage = "VBScript";//not sure <br />
about this <br />
                        oStep.AddGlobalVariables = true; <br />
                        oStep.CloseConnection = false; <br />
                        oStep.ExecuteInMainThread = true; <br />
                        oStep.IsPackageDSORowset = false; <br />
                        oStep.JoinTransactionIfPresent = false; <br />
                        oStep.DisableStep = false; <br />
                        oStep.FailPackageOnError = true; <br />
                        package.Steps.Add(oStep); <br />
                        oStep = null; <br />
                        DTS.Task oTask = <br />
(DTS.Task)package.Tasks.New("D­­TSDataPumpTask"); <br />
                        oTask.Name = "Copying Data from MyTable"; <br />
                        DTS.CustomTask oCustomTask = oTask.CustomTask; <br />
                        oCustomTask.Name = "Copying Data from MyTable"; <br />
<br />
<br />
                        oCustomTask.Description = "Copying Data from <br />
MyTable to <br />
MyDestDB.MyTable"; <br />
                        DTS.DataPumpTask DT = <br />
(DTS.DataPumpTask)package.Task­­s.New("DTSDataPumpTask"); <br />
                        DT.SourceConnectionID = 1; <br />
                        DT.SourceSQLStatement = "SELECT `TestField` <br />
FROM MyTable"; <br />
                        DT.DestinationConnectionID =2; <br />
                        DT.DestinationObjectName = "MyTable"; <br />
                        DT.ProgressRowCount = 1000; <br />
                        DT.MaximumErrorCount = 0; <br />
                        DT.FetchBufferSize = 1; <br />
                        DT.UseFastLoad=true; <br />
                        DT.InsertCommitSize = 0; <br />
                        DT.InsertCommitSize = 500000; <br />
                        DT.ExceptionFileColumnDelimite­­r = "|"; <br />
                        DT.ExceptionFileRowDelimiter = "\r\n"; <br />
                        DT.AllowIdentityInserts = false; <br />
                        DT.FirstRow = 0; <br />
                        DT.LastRow = 0; <br />
                        DTS.Transformation Trans = <br />
(DTS.Transformation)package.Ta­­sks.New("DataPumpTransformCop­y­"); <br />
                        Trans.Name = "DirectCopyXform"; <br />
                        Trans.TransformFlags = 63; <br />
                        Trans.ForceSourceBlobsBuffered = 0; <br />
                        Trans.ForceBlobsInMemory = false; <br />
                        Trans.InMemoryBlobSize = 1048576; <br />
                        Trans.SourceColumns.AddColumn(­­"TestField",1); <br />
<br />
<br />
Trans.DestinationColumns.AddCo­­lumn("TestField",1); <br />
                        DT.Transformations.Add(Trans); <br />
                        package.Tasks.Add(oTask); <br />
                        oCustomTask = null; <br />
                        oTask = null; <br />
<br />
<br />
                } <br />
<br />

GeneralRe: Creating DTS Packages in C# Pin
JMichael24688-Aug-05 8:27
JMichael24688-Aug-05 8:27 
Generalreading XML from a string Pin
Mridang Agarwalla8-Aug-05 3:01
Mridang Agarwalla8-Aug-05 3:01 
GeneralRe: reading XML from a string Pin
Anonymous8-Aug-05 4:14
Anonymous8-Aug-05 4:14 
GeneralMultiple calls to same function Pin
Dwayner798-Aug-05 2:33
Dwayner798-Aug-05 2:33 
GeneralRe: Multiple calls to same function Pin
Alomgir Miah8-Aug-05 10:44
Alomgir Miah8-Aug-05 10:44 
GeneralRe: Multiple calls to same function Pin
Dwayner799-Aug-05 5:21
Dwayner799-Aug-05 5:21 
QuestionInsert Null to Foxpro table with DataSet? Pin
Member 18559638-Aug-05 1:49
Member 18559638-Aug-05 1:49 
GeneralWebBrowser security level Pin
gnjunge8-Aug-05 1:27
gnjunge8-Aug-05 1:27 
Generalcreating a programming software package Pin
Atmadarshini8-Aug-05 1:17
Atmadarshini8-Aug-05 1:17 
GeneralRe: creating a programming software package Pin
Steve S8-Aug-05 1:40
Steve S8-Aug-05 1:40 
GeneralRe: creating a programming software package Pin
Atmadarshini8-Aug-05 1:45
Atmadarshini8-Aug-05 1:45 
GeneralRe: creating a programming software package Pin
Steve S15-Aug-05 0:37
Steve S15-Aug-05 0:37 
Generalview Pin
magnifique8-Aug-05 1:05
magnifique8-Aug-05 1:05 
GeneralRobocopy C# Pin
NitinR8-Aug-05 0:36
NitinR8-Aug-05 0:36 
GeneralRe: Robocopy C# Pin
gnjunge8-Aug-05 1:36
gnjunge8-Aug-05 1:36 
GeneralRe: Robocopy C# Pin
NitinR8-Aug-05 1:41
NitinR8-Aug-05 1:41 
GeneralRe: Robocopy C# Pin
Member 77568542-Jun-11 5:13
Member 77568542-Jun-11 5:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.