Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on an environment that I don't have Microsoft Office installed, but the access runtime is installed.

The scenario is that I have an access file containing linked tables to excel and my problem is the way to update the connection string of these linked tables.

I have created a module function and a macro in order to do the update.

The problem is to call the macro or the module function function in a way without creating an access object because doing so will raise an COM exception.

If there a problem to my solution? If not what are the alternatives?
Posted

See if this[^] helps.
 
Share this answer
 
I have found a solution that I have adopted in my solution.

public void UpdateLinkedTablesConnectionString()
        {
            try
            {
                //Get the excel file location from the directory of the current assembly since the .accdb and the .xlsx are in the same directory location.
                string currentAssemblyDirectoryName = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                StringBuilder strPath = new StringBuilder();
                strPath.Append(currentAssemblyDirectoryName);
                strPath.Append(Common.GetResourceValue(_directory_DataInput, false, null));
                strPath.Append(Common.GetResourceValue(_excelFileName, false, string.Empty));

                ADODB.Connection Con = new ADODB.Connection();
                Con.ConnectionString = myAccessDatabase.ConnectionString;
                ADOX.Catalog Cat = new ADOX.Catalog();

                Con.Open();
                Cat.ActiveConnection = Con;
                List<string> lstLinkedTablesNames = GetTablesNames();
                foreach (string name in lstLinkedTablesNames )
                {
                    Cat.Tables[name].Properties["Jet OLEDB:Link Datasource"].Value = strPath.ToString(); 
                }
                
                Con.Close();  
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900