Calling BTEQ script from a .NET Application
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


Calling BTEQ script from a .NET Application Expand / Collapse
Author
Message
Posted 5/14/2008 2:43:17 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 5/14/2008 1:14:34 PM
Posts: 2, Visits: 9
Hi all,

Is there a way to call a BTEQ script from a .NET application and if so is it possible to pass parameters to the BTEQ script in any way....

Thanks in advance for the inputs...

Thanks,
Arun



Arun Sankar S
Post #11431
Posted 5/21/2008 6:11:32 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: Today @ 7:30:07 AM
Posts: 197, Visits: 611
Hello,

Have a look at "System.Diagnostics.Process" class in .NET. Using that you can run BTEQ and pass arguments to it, or you can directly run "BTEQ < scriptname.btq".

Regards,

Adeel
Post #11521
Posted 7/16/2008 12:17:56 PM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 11/18/2008 2:43:07 PM
Posts: 31, Visits: 41
Arun,
Below is a pair of classes that I use to run BTEQ from C#. It's pretty simple really. You create a BTEQJob object and set the LogFileName and the SQLFileName properties and then call the Start Method. It is a bit more complicated than using redirection from the operating system, but you have more control.

R

===========================================================

using System.Diagnostics;
using System.IO;


/*This is just used to log the output from the BTEQ Process */
static class JobLog
{
static object locker = new object();
static public void Writer(String LogFile, String Message)
{
lock (locker)
using (StreamWriter sw = new StreamWriter(LogFile, true))
{
sw.WriteLine(String.Format("{0:G}\t{1}", DateTime.Now, Message));
sw.Flush();
sw.Close();
}
}
}

class BTEQJob
{
private String BTEQ = @"C:\Program Files\NCR\Teradata Client\bin\bteq.exe";
public String LogFileName = String.Empty;
public String SQLFileName = String.Empty;
private Process BTEQProcess;

public void Start()
{
File.Delete(LogFileName);

BTEQProcess = new Process();
BTEQProcess.StartInfo.FileName = BTEQ;
BTEQProcess.StartInfo.CreateNoWindow = true;


/* Redirect StdIO */
BTEQProcess.StartInfo.UseShellExecute = false;
BTEQProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(SQLFileName);
BTEQProcess.StartInfo.RedirectStandardInput = true;
BTEQProcess.StartInfo.RedirectStandardOutput = true;
BTEQProcess.StartInfo.RedirectStandardError = true;

/* Handle process events */
/* I log STDERR and STDOUT to the same log file */
BTEQProcess.EnableRaisingEvents = true;
BTEQProcess.OutputDataReceived += new DataReceivedEventHandler(BTEQProcess_OutputDataReceived);
BTEQProcess.ErrorDataReceived += new DataReceivedEventHandler(BTEQProcess_OutputDataReceived);
BTEQProcess.Exited += new EventHandler(BTEQProcess_Exited);

/* Start This Puppy */
BTEQProcess.Start();
BTEQProcess.BeginOutputReadLine();
BTEQProcess.BeginErrorReadLine();
using (StreamReader sr = new StreamReader(SQLFileName))
{
BTEQProcess.StandardInput.WriteLine(sr.ReadToEnd());
sr.Close();
}
}

private void BTEQProcess_Exited(object sender, EventArgs e)
{
//Console.WriteLine(Program.BTEQCnt.ToString());
if (BTEQProcess.ExitCode > 0)
{
Program.CurrentExitCode = BTEQProcess.ExitCode;
Program.FailedScript = Path.GetFileName(SQLFileName);
}
Program.BTEQCnt--;
}

private void BTEQProcess_OutputDataReceived(object sendingProcess, DataReceivedEventArgs outLine)
{
if (!String.IsNullOrEmpty(outLine.Data))
JobLog.Writer(LogFileName, outLine.Data);
}

}
Post #12118
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 2 ( 2 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 3:52pm

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.078. 9 queries. Compression Disabled.