Using LCOPY to insert data into vertica

Moderator: NorbertKrupa

Post Reply
ajit_nayak
Newbie
Newbie
Posts: 15
Joined: Tue May 14, 2013 1:25 pm

Using LCOPY to insert data into vertica

Post by ajit_nayak » Fri Dec 13, 2013 1:27 pm

Hi,

I have tried the LCOPY command to insert data to vertica database from a tab delimited file in my system.
No need to add the file to Linux vertica machine,it works for me through ODBC connection.

Code: Select all

---Provide Created DSN for ODBC( args[0]), Data File Path(args[1]), Rejected File Path(args[2])
 string dsn = string.Format("Provider=vertica;DSN={0}", args[0]);
            OdbcConnection odconn = new OdbcConnection(dsn);
            string lcopy = string.Format(@"LCOPY test FROM '{0}' REJECTEDFILE '{1}' DELIMITER E'\t';", args[1], args[2]);

            OdbcCommand cmd = new OdbcCommand(lcopy, odconn);
            try
            {
                odconn.Open();
                OdbcTransaction trans = odconn.BeginTransaction();
                cmd.Transaction = trans;
                cmd.ExecuteNonQuery();
                trans.Commit();
                Console.WriteLine("Data Inserted");
            }
            catch
            {
                Console.WriteLine("Data Insertion Error");
            }

Post Reply

Return to “ADO.NET”