I am trying to connect to Teradata with c#. I am using the sample code from this website
using System;
using System.Collections.Generic;
using System.Text;
using Teradata.Client.Provider;
namespace Teradata.Client.Provider.HelloWorld
{
class HelloWorld
{
static void Main(string[] args)
{
using (TdConnection cn = new TdConnection("Data Source = x;User ID = y;Password = z;"))
{
cn.Open();
TdCommand cmd = cn.CreateCommand();
cmd.CommandText = "SELECT DATE";
using (TdDataReader reader = cmd.ExecuteReader())
{
reader.Read();
DateTime date = reader.GetDate(0);
Console.WriteLine("Teradata Database DATE is {0}", date);
}
}
}
}
}
(I have also tried DSN , UID , PWD
However, I am getting exception that either my userid , account or password not correct ...
But I am able to login using SQL Assistant easily. So , I rule out incorrect userid or password
Here I found a possible solution for my problem But I do not know what exactly I need to change in my sample code.
So, I have no idea how to implement that solution.
Can anybody give me a working sample code?
Based on the link you posted, changing the Authentication Mechanism to LDAP might work.
TdConnectionStringBuilder connectionStringBuilder = new TdConnectionStringBuilder();
connectionStringBuilder.DataSource = "x";
connectionStringBuilder.Database = "DATABASENAME";
connectionStringBuilder.UserId = "y";
connectionStringBuilder.Password = "z";
connectionStringBuilder.AuthenticationMechanism = "LDAP";
using (TdConnection cn = new TdConnection())
{
cn.ConnectionString = connectionStringBuilder.ConnectionString;
cn.Open();
TdCommand cmd = cn.CreateCommand();
cmd.CommandText = "SELECT DATE";
using (TdDataReader reader = cmd.ExecuteReader())
{
reader.Read();
DateTime date = reader.GetDate(0);
Console.WriteLine("Teradata Database DATE is {0}", date);
}
}