Click here to Skip to main content
16,019,018 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to insert data into mdb from mdb.It is work properly on my local(LAN area) but problem is when i insert data on my remote system(using static ip) file not access(not exist).
My code below.

What I have tried:

C#
DataTable schemaTable;
        OleDbConnection connn = new OleDbConnection();
        OleDbCommand cmdD = new OleDbCommand();
        connn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;" +
               @"Data source=D:\TDATA\att2000.mdb";
        connn.Open();
        cmdD.Connection = connn;
        //data source=\\static ip\D:\db\att2000.mdb;Persist Security Info=False"
        string templetDataTable = @"\\static ip here\D:\db\att2000.mdb;Persist Security Info=False";
        string clientDataTable = @"D:\TDATA\att2000.mdb";
        string templetBackupDataTable = @"D:\TDATA\att2000.mdb";
        if (File.Exists(templetDataTable))
        {   //**********MDB Data Migration**************//
            schemaTable = connn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
                         new Object[] { null, null, null, "TABLE" });
            //1. Copy Existing Data from  Clientfolder to the New Templet
            for (int i = 0; i < 1; i++)
            {
                string query = "INSERT INTO " + schemaTable.Rows[29].ItemArray[2].ToString() + " IN '" + templetDataTable + "' SELECT * FROM " + schemaTable.Rows[4].ItemArray[2].ToString() +"";
                cmdD.CommandType = CommandType.Text;
                cmdD.CommandText = query;
                try
                {
                    cmdD.ExecuteNonQuery();
                    this.RegisterStartupScript("clientScript", ObjERP.strScr1 + "DATA MODIFY SUCESSFULLY" + ObjERP.strScr2);

                }
                catch (Exception ex)
                {
                    //txtErrorDetails.Visible = true;
                    //txtErrorDetails.Text = ex.ToString();
                    //errorLogger = new StreamWriter(@"ErrorLog" + DateTime.Now.ToString("ddMMyyyyMMhhss") + ".Log");
                    //errorLogger.WriteLine(txtErrorDetails.Text + " \n Error While Updating Table.."
                    //                       + schemaTable.Rows[i].ItemArray[2].ToString() + "{" + ex.ToString() + "}");
                    //errorLogger.Flush();
                    //continue;
                }
            }

            connn.Close();
            try
            {
                //2. Move Client MDB to seperate folder
                File.Move(clientDataTable, templetBackupDataTable);
                //3. Move Updated templet MDB to Client application data folder
                File.Move(templetDataTable, clientDataTable);
                //4. Delete old Client MDB 
                 File.Delete(templetBackupDataTable);
            }
            catch (Exception ex)
            {
            }
        }
Posted
Updated 23-Mar-16 6:58am
v2
Comments
Richard MacCutchan 17-Mar-16 5:55am    
Make sure the folder and file are both accessible to you via sharing.
ArvindTomar 17-Mar-16 6:32am    
yes both are accessible
F-ES Sitecore 23-Mar-16 13:29pm    
You've put "\\static ip here\D:\db\att2000.mdb" into WIndows Explorer or the "run" box and the database opens?

1 solution

The line
C#
string templetDataTable = @"\\static ip here\D:\db\att2000.mdb;Persist Security Info=False";

should probably read
C#
string templetDataTable = @"\\static ip here\db\att2000.mdb;Persist Security Info=False";
I.e. remove the D:\ or replace it with the name of the Share
 
Share this answer
 
Comments
F-ES Sitecore 23-Mar-16 13:30pm    
Or possibly

@"\static ip here\D$\db\att2000.mdb;Persist Security Info=False";
CHill60 23-Mar-16 14:06pm    
Yes - good example of inserting the share name instead of the drive mapping

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