How to set up .net teradata connection in c#?

前端 未结 4 2442
天命终不由人
天命终不由人 2021-02-14 12:36

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;
usin         


        
相关标签:
4条回答
  • 2021-02-14 13:16

    Try this

                    TdConnectionStringBuilder builder=new TdConnectionStringBuilder();
                    builder.Add("Data Source", "xxx");
                    builder.Add("User ID", "vvv");
                    builder.Add("Password", "bbb");
                    TdConnection cn = new TdConnection(builder.ConnectionString);
                    cn.Open();
    
    0 讨论(0)
  • 2021-02-14 13:19

    Copy paste this.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Teradata.Client.Provider;
    
    namespace Teradata.Client.Provider.ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                TdConnection cn = new TdConnection();
                TdConnectionStringBuilder conStrBuilder = new TdConnectionStringBuilder();
    
                conStrBuilder.DataSource = "DSN";
                // conStrBuilder.Database = "optional";
    
                conStrBuilder.UserId = "user"; conStrBuilder.Password = "pass";
                cn.ConnectionString = conStrBuilder.ConnectionString;
    
                cn.Open();
    
                Console.WriteLine("connection successfull");
            }
        }
    }
    
    0 讨论(0)
  • 2021-02-14 13:22

    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);
        }
    }
    
    0 讨论(0)
  • 2021-02-14 13:28

    Try this. try to see if you get anything in the string 'tt'. Plz change your DBCommand query to whatever relevant.

        public readonly String sUser = "UserName";
        public readonly String sPassword = "Password";
        public readonly String sDataSource = "IP Address"; 
        public readonly String sConnection = "Data Source=" + sDataSource + ";User ID=" + sUser + ";Password=" + sPassword;
    
    
            DbProviderFactory pf = DbProviderFactories.GetFactory("Teradata.Client.Provider");
            DbConnection con = pf.CreateConnection();
            con.ConnectionString = sConnection ;       
            DbCommand cmd= new DbCommand("select top 10 * from tdb.access_method");
            DbCommand Db = (DbCommand)cmd;
            Db.Connection = con;
            DataSet ds = new DataSet();
            con.Open();
            string tt = (string)Db.ExecuteScalar();
    
    0 讨论(0)
提交回复
热议问题