如何设置在C#.NET的Teradata连接? [英] How to set up .net teradata connection in c#?

查看:517
本文介绍了如何设置在C#.NET的Teradata连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用C#连接到Teradata的。我这个网站利用示例代码

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);
                 }
             }
         }
    }
}

(我也曾尝试 DSN,UID,PWD
但是,我得到的例外,无论是我的用户ID,帐号或密码不正确 ...
,而我能够很容易地使用SQL助理进行登录。所以,我排除了不正确的用户ID或密码

(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我发现我的问题
可能的解决办法,但我不知道究竟是什么我需要在我的示例代码来改变。

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?

推荐答案

根据您发布的链接,改变了认证机制LDAP可能工作

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);
    }
}

这篇关于如何设置在C#.NET的Teradata连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆