Yes,I staged the data in sql server and delete duplicate records. Now, I need to truncate the Access database table to load the data. Is there any other way to truncate the access database table except using script components. I do not know how to
write VB or C# scripts for Script component and I looked at the blog post, I could not find out what I need to replace on the codes posted .
Here was code to truncate or detele table from access using VB. Do you know what are the codes I need to change here. I know I need to mention my table name here. what else I need to change in the code.
DO i need to change here: Dim cm As ConnectionManager = Dts.Connections("AccessDB")
In place of "AccessDB" do I need to give my access database connection name in ssis package?
colTables = conn.GetSchema("Tables")
Do I need to Change "Tables" ?
If Left(objTable.Item("Table_name").ToString, 4) <> "MSys" Then
sql = "Delete from " & conn.DataSource.ToString & "." & objTable.Item("Table_Name").ToString
I believe I need to change "Table_name" to my access db table name which is called ALL.
Your help is appreciated.
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports System.Data.OleDb
Imports Microsoft.Office.Interop.Access
<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Public Sub Main()
Dim cm As ConnectionManager = Dts.Connections("AccessDB")
Dim cmParam As Wrapper.IDTSConnectionManagerDatabaseParameters100
Dim conn As OleDb.OleDbConnection
cmParam = CType(cm.InnerObject, Wrapper.IDTSConnectionManagerDatabaseParameters100)
conn = CType(cmParam.GetConnectionForSchema(), OleDb.OleDbConnection)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
'Get Tables From AccessDatabase
Dim colTables As DataTable
Dim objTable As DataRow
Dim sql As String
Dim cmd As OleDbCommand
colTables = conn.GetSchema("Tables")
For Each objTable In colTables.Rows
If Left(objTable.Item("Table_name").ToString, 4) <> "MSys" Then
sql = "Delete from " & conn.DataSource.ToString & "." & objTable.Item("Table_Name").ToString
'MsgBox(sql)
cmd = New OleDbCommand(sql, conn)
cmd.ExecuteNonQuery()
End If
Next
Dts.TaskResult = ScriptResults.Success
End Sub
End Class