2

I have a single MS Access .mdb file that contains multiple tables like

Table name:

UserLog_1_2019
UserLog_2_2019
User_Log_3_2019

For every month new table generate automatically.

I want to import above mentioned dynamically tables into SQL Server by using SSIS. How to achieve this scenario?

Thanks, Lawrance A

Yahfoufi
  • 2,220
  • 1
  • 22
  • 41

1 Answers1

1

In this answer i will provide 2 approaches to achieve this:

  1. using SSIS
  2. using C#

(1) SSIS approach

You must get the Access tables list into a variable of type System.Object, then loop over the tables names using a Foreach Loop container. There are many links that gives detailed informations, as example you can refer to the following SO answer it can gives you some insights:

(2) C# approach

Recently i started a new project on Git-Hub, which is a class library developed using C#. You can use it to import tabular data from excel, word , powerpoint, text, csv, html, json and xml into SQL server table having a different schema definition using schema mapping approach. check it out at:

You can use a similar code:

string con = @"Data Source=.\SQLInstance;Initial Catalog=tempdb;integrated security=SSPI;";

using (SchemaMapperDLL.Classes.Converters.MsAccessImport smAccess = new SchemaMapperDLL.Classes.Converters.MsAccessImport(@"U:\Passwords.mdb"))
{
    using (SchemaMapperDLL.Classes.SchemaMapping.SchemaMapper SM = new SchemaMapperDLL.Classes.SchemaMapping.SchemaMapper("dbo","passwords"))
    {
        SM.CreateDestinationTable(con);
        //Read Access
        smAccess.BuildConnectionString();
        smAccess.getSchemaTable();

        foreach (DataRow schRow in smAccess.SchemaTable.Rows)
        {
            string strTablename = schRow["TABLE_NAME"].ToString().Trim('\'');

            DataTable dt = smAccess.GetTableByName(strTablename);
            bool result = SM.ChangeTableStructure(ref dt);

            if (result == true)
            {
                SM.InsertToSQLUsingSQLBulk(dt, con);
            }
        }
    }
}
Hadi
  • 36,233
  • 13
  • 65
  • 124